<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/61558>61558</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Segfault while trying to compile unsupported c++ modules code
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
szaszm
</td>
</tr>
</table>
<pre>
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).
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzUWVtz3KiX_zTyC0WXhC4tPfih7U5PXJvspOJs5tGF4EjNBIEGkN2eh_3sWyD1RW2P7aQyqf2nHFs6gsPv3A9ArRWtAriM8qsoX1_QwW21ubR_U_t3d1Fr_nh5gx6oRQ6sE6pFD1twWzCIoi1IqdGDNpKjB-G2iEXkKiJXqNN8kGCRsMgOfa-NA47qR8QkVW1ErlE9OASK6UE5MMARRcxQu0V8MH6J3kBvNANrhWoXUbyO4tX4m-muo4ojKRRE6WrPMayK9YQIW8ejdD2hITXCzR4RbkTXS8GEwyMJd7T35N5APQh5IPfUbaN0vSefjjjjYI_sMaNse5gbXkZIC9b3p2LcoD8H6xDT_SPuqfXqcVtAjaStRY3RXXiN8quP0xI9bSHK1xEpt871NkpXEdlEZBPkX0h53y20aSOy4ZrZiGymeYut62RE0sErEp_JaCNSeWN40-nBIQOUe-1rgwbFwVhHFR8tTp0H9Ig6oGqB_pgmeIy4GVF7RsJFZGlRQ4X001pDGTSDlI8zE1o9GOaNNxGLePw5qEh03mNQMOLV6UyhHOqoUBEpI1KhaHn4WoXBqyhd9UYoJ8ch5L3XfRDR-2hEkogQL_SB7XJ9BuJ0OT24fnBPgU5ihAC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