<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/101398>101398</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Assertion failure when compiling non-module as a module
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          davidstone
      </td>
    </tr>
</table>

<pre>
    The following translation unit:

```c++
// lol
```

when compiled with `-x c++-module`

causes clang to crash with

```console
clang-20: /root/llvm-project/clang/lib/Serialization/GeneratePCH.cpp:107: virtual clang::Module* clang::CXX20ModulesGenerator::getEmittingModule(clang::ASTContext&): Assertion `M && M->isNamedModuleUnit() && "CXX20ModulesGenerator should only be used with C++20 Named modules."' failed.
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: /opt/compiler-explorer/clang-assertions-trunk-20240731/bin/clang-20 -cc1 -triple x86_64-unknown-linux-gnu -emit-module-interface -disable-free -clear-ast-before-backend -main-file-name example.cpp -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -fno-verbose-asm -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debug-info-kind=constructor -dwarf-version=4 -debugger-tuning=gdb -fdebug-compilation-dir=/app -fcoverage-compilation-dir=/app -resource-dir /opt/compiler-explorer/clang-assertions-trunk-20240731/lib/clang/20 -internal-isystem /opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/15.0.0/../../../../include/c++/15.0.0 -internal-isystem /opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/15.0.0/../../../../include/c++/15.0.0/x86_64-linux-gnu -internal-isystem /opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/15.0.0/../../../../include/c++/15.0.0/backward -internal-isystem /opt/compiler-explorer/clang-assertions-trunk-20240731/lib/clang/20/include -internal-isystem /usr/local/include -internal-isystem /opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/15.0.0/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -std=c++23 -fdeprecated-macro -ferror-limit 19 -fgnuc-version=4.2.1 -fno-implicit-modules -fskip-odr-check-in-gmf -fcxx-exceptions -fexceptions -fcolor-diagnostics -mllvm --x86-asm-syntax=intel -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/example-7b0746.pcm -x c++ <source>
1.      <eof> parser at end of file
 #0 0x0000000003a82e08 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk-20240731/bin/clang-20+0x3a82e08)
 #1 0x0000000003a8057c SignalHandler(int) Signals.cpp:0:0
 #2 0x00007ea09aa42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #3 0x00007ea09aa969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #4 0x00007ea09aa42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #5 0x00007ea09aa287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #6 0x00007ea09aa2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
 #7 0x00007ea09aa39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
 #8 0x00000000048851ab clang::CXX20ModulesGenerator::getEmittingModule(clang::ASTContext&) (/opt/compiler-explorer/clang-assertions-trunk-20240731/bin/clang-20+0x48851ab)
 #9 0x00000000048852ac clang::PCHGenerator::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-assertions-trunk-20240731/bin/clang-20+0x48852ac)
#10 0x00000000048853c1 clang::CXX20ModulesGenerator::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-assertions-trunk-20240731/bin/clang-20+0x48853c1)
#11 0x000000000465b8b8 clang::MultiplexConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-assertions-trunk-20240731/bin/clang-20+0x465b8b8)
#12 0x0000000006478aac clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk-20240731/bin/clang-20+0x6478aac)
#13 0x0000000004621529 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk-20240731/bin/clang-20+0x4621529)
#14 0x00000000045a5d5e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk-20240731/bin/clang-20+0x45a5d5e)
#15 0x000000000470a81e clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk-20240731/bin/clang-20+0x470a81e)
#16 0x0000000000c8340f cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk-20240731/bin/clang-20+0xc8340f)
#17 0x0000000000c7c59a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#18 0x0000000000c7fece clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk-20240731/bin/clang-20+0xc7fece)
#19 0x0000000000b54a74 main (/opt/compiler-explorer/clang-assertions-trunk-20240731/bin/clang-20+0xb54a74)
#20 0x00007ea09aa29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#21 0x00007ea09aa29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#22 0x0000000000c7c04e _start (/opt/compiler-explorer/clang-assertions-trunk-20240731/bin/clang-20+0xc7c04e)
clang++: error: unable to execute command: Aborted (core dumped)
clang++: error: clang frontend command failed due to signal (use -v to see invocation)
Compiler returned: 254
```

See it live: https://godbolt.org/z/eToKnErao
</pre>
<img width="1px" height="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