Issue 61558
Summary Segfault while trying to compile unsupported c++ modules code
Labels new issue
Assignees
Reporter szaszm
    I was testing whether a hello world with c++ modules is supported by clang, but encountered a crash during preprocessing.

command line: clang++ -o hello -std=c++2b -fmodules -fimplicit-module-maps -fprebuilt-module-path=prebuilt -fprebuilt-implicit-modules -fmodules-cache-path=cache hello.cpp

I just copy-pasted the flags from the [Modules page](https://clang.llvm.org/docs/Modules.html#using-prebuilt-modules), without reading or understanding what they mean. Without the -f flags, it's failing gracefully.

source:
```cpp
import std;

int main() {
	std::println("Hello, world!");
}
```

output:
```
szaszm@szaszm-pc:~$ clang++ -o hello -std=c++2b -fmodules -fimplicit-module-maps -fprebuilt-module-path=prebuilt -fprebuilt-implicit-modules -fmodules-cache-path=cache hello.cpp
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0. Program arguments: /usr/bin/clang-15 -cc1 -triple x86_64-pc-linux-gnu -emit-obj -mrelax-all --mrelax-relocations -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file
-name hello.cpp -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -mllv
m -treat-scalable-fixed-error-as-warning -debugger-tuning=gdb -fcoverage-compilation-dir=/home/szaszm -resource-dir /usr/lib/clang/15.0.7 -internal-isystem /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/12.2.1/../../../.
./include/c++/12.2.1 -internal-isystem /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/12.2.1/../../../../include/c++/12.2.1/x86_64-pc-linux-gnu -internal-isystem /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/12.2.1/../../../
../include/c++/12.2.1/backward -internal-isystem /usr/lib/clang/15.0.7/include -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/12.2.1/../../../../x86_64-pc-linux-gnu/
include -internal-externc-isystem /include -internal-externc-isystem /usr/include -std=c++2b -fdeprecated-macro -fdebug-compilation-dir=/home/szaszm -ferror-limit 19 -stack-protector 2 -fgnuc-version=4.2.1 -fmodules
 -fimplicit-module-maps -fmodules-cache-path=cache -fprebuilt-module-path=prebuilt -fprebuilt-implicit-modules -fmodules-validate-system-headers -fcxx-exceptions -fexceptions -fcolor-diagnostics -faddrsig -D__GCC_HA
VE_DWARF2_CFI_ASM=1 -o /tmp/hello-aab6e2.o -x c++ hello.cpp
1.      hello.cpp:1:11: current parser token ';'
 #0 0x00007f3159bf3aaa (/usr/lib/libLLVM-15.so+0xd7baaa)
 #1 0x00007f3159bf113f llvm::sys::RunSignalHandlers() (/usr/lib/libLLVM-15.so+0xd7913f)
 #2 0x00007f3159bf128d (/usr/lib/libLLVM-15.so+0xd7928d)
 #3 0x00007f3158a91f50 (/usr/lib/libc.so.6+0x38f50)
 #4 0x00007f3160f20814 clang::ModuleMap::getModuleMapFileForUniquing(clang::Module const*) const (/usr/lib/libclang-cpp.so.15+0x7ea814)
 #5 0x00007f3160f209a9 clang::HeaderSearch::getPrebuiltImplicitModuleFileName[abi:cxx11](clang::Module*) (/usr/lib/libclang-cpp.so.15+0x7ea9a9)
 #6 0x00007f31625ce248 clang::CompilerInstance::findOrCompileModuleAndReadAST(llvm::StringRef, clang::SourceLocation, clang::SourceLocation, bool) (/usr/lib/libclang-cpp.so.15+0x1e98248)
 #7 0x00007f31625cf835 clang::CompilerInstance::loadModule(clang::SourceLocation, llvm::ArrayRef<std::pair<clang::IdentifierInfo*, clang::SourceLocation>>, clang::Module::NameVisibilityKind, bool) (/usr/lib/libclang-cpp.so.15+0x1e99835)
 #8 0x00007f3160f760d6 clang::Preprocessor::LexAfterModuleImport(clang::Token&) (/usr/lib/libclang-cpp.so.15+0x8400d6)
 #9 0x00007f3160f62803 clang::Preprocessor::Lex(clang::Token&) (/usr/lib/libclang-cpp.so.15+0x82c803)
#10 0x00007f3160f62b88 clang::Preprocessor::CachingLex(clang::Token&) (/usr/lib/libclang-cpp.so.15+0x82cb88)
#11 0x00007f3160f6276b clang::Preprocessor::Lex(clang::Token&) (/usr/lib/libclang-cpp.so.15+0x82c76b)
#12 0x00007f3161031255 clang::Parser::ParseModuleName(clang::SourceLocation, llvm::SmallVectorImpl<std::pair<clang::IdentifierInfo*, clang::SourceLocation>>&, bool) (/usr/lib/libclang-cpp.so.15+0x8fb255)
#13 0x00007f3161031be6 clang::Parser::ParseModuleImport(clang::SourceLocation, clang::Sema::ModuleImportState&) (/usr/lib/libclang-cpp.so.15+0x8fbbe6)
#14 0x00007f31610334b0 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/usr/lib/libclang-cpp.so.15+0x8fd4b0)
#15 0x00007f3161033748 clang::Parser::ParseFirstTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/usr/lib/libclang-cpp.so.15+0x8fd748)
#16 0x00007f3160f7f134 clang::ParseAST(clang::Sema&, bool, bool) (/usr/lib/libclang-cpp.so.15+0x849134)
#17 0x00007f316261d479 clang::FrontendAction::Execute() (/usr/lib/libclang-cpp.so.15+0x1ee7479)
#18 0x00007f31625c314f clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/usr/lib/libclang-cpp.so.15+0x1e8d14f)
#19 0x00007f316268809a clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/usr/lib/libclang-cpp.so.15+0x1f5209a)
#20 0x0000559a3a3bd4d0 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/usr/bin/clang-15+0x104d0)
#21 0x0000559a3a3c3197 (/usr/bin/clang-15+0x16197)
#22 0x0000559a3a3c3a27 clang_main(int, char**) (/usr/bin/clang-15+0x16a27)
#23 0x00007f3158a7c790 (/usr/lib/libc.so.6+0x23790)
#24 0x00007f3158a7c84a __libc_start_main (/usr/lib/libc.so.6+0x2384a)
#25 0x0000559a3a3b9d25 _start (/usr/bin/clang-15+0xcd25)
clang-15: error: unable to execute command: Segmentation fault (core dumped)
clang-15: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 15.0.7
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
clang-15: error: unable to execute command: Segmentation fault (core dumped)
clang-15: note: diagnostic msg: Error generating preprocessed source(s).
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to