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

    <tr>
        <th>Summary</th>
        <td>
            [clang] Assertion `ModuleScopes.size() <= 1 && "expected to be at global module scope"' failed.
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            c++20,
            clang:frontend,
            crash-on-invalid,
            clang:frontend:fuzzer
      </td>
    </tr>

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

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

<pre>
    **This testcase is generated by a fuzzer.**

Compiler Explorer: [https://godbolt.org/z/vKr6oPYrq](https://godbolt.org/z/vKr6oPYrq)

This invalid code will crash on Clang Assertion Trunk.
```cpp
export module a;
module :private;
export module a:part;
module;
```

It seems that this goes back to clang-10.

Stack dump:
```
clang++: /root/llvm-project/clang/lib/Sema/SemaModule.cpp:314: clang::Sema::DeclGroupPtrTy clang::Sema::ActOnModuleDecl(clang::SourceLocation, clang::SourceLocation, clang::Sema::ModuleDeclKind, clang::ModuleIdPath, clang::ModuleIdPath, clang::Sema::ModuleImportState&): Assertion `ModuleScopes.size() <= 1 && "expected to be at global module scope"' 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/bin/clang++ -gdwarf-4 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -fno-verbose-asm -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics -std=c++20 <source>
1.      <source>:4:1: current parser token 'module'
 #0 0x0000000003be9e28 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3be9e28)
 #1 0x0000000003be7b2c llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3be7b2c)
 #2 0x0000000003b35468 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x0000752e91e42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x0000752e91e969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #5 0x0000752e91e42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #6 0x0000752e91e287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #7 0x0000752e91e2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
 #8 0x0000752e91e39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
 #9 0x0000000006fb07a5 clang::Sema::ActOnModuleDecl(clang::SourceLocation, clang::SourceLocation, clang::Sema::ModuleDeclKind, llvm::ArrayRef<std::pair<clang::IdentifierInfo*, clang::SourceLocation>>, llvm::ArrayRef<std::pair<clang::IdentifierInfo*, clang::SourceLocation>>, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6fb07a5)
#10 0x00000000066ef411 clang::Parser::ParseModuleDecl(clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x66ef411)
#11 0x00000000066f29b6 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x66f29b6)
#12 0x00000000066e4c5a clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x66e4c5a)
#13 0x0000000004563b58 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4563b58)
#14 0x000000000481e689 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x481e689)
#15 0x000000000479d8fe clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x479d8fe)
#16 0x000000000490441e clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x490441e)
#17 0x0000000000ce624f cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xce624f)
#18 0x0000000000cddf0a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#19 0x00000000045a6cb9 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#20 0x0000000003b35914 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3b35914)
#21 0x00000000045a72af clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0
#22 0x000000000456d63d clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x456d63d)
#23 0x000000000456e72d clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x456e72d)
#24 0x0000000004575ae5 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4575ae5)
#25 0x0000000000ce30e9 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xce30e9)
#26 0x0000000000bb0284 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xbb0284)
#27 0x0000752e91e29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#28 0x0000752e91e29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#29 0x0000000000cdd9be _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xcdd9be)
clang++: error: clang frontend command failed with exit code 134 (use -v to see invocation)
Compiler returned: 134
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzkWV9v47gR_zTMCyFDov5YesiD1omvudvigktQoE8GRY1s3sqkjqS8Tj59QUp2ROVPN0WyLdBDbuOQw5nf_GY4HJpUa74VAJco_YLSqwvam51Ulw_8TyqSPEkvKlk_XCJSIlLe77jGBrRhVAPmGm9BgKIGalw9YIqb_vER1GIQRuEVCsd_V3Lf8RYUvj52rVSgUFxilH7ZGdNpFJeIrBFZb2VdydYspNoisn5EZH34TWXy9p_qL5ReIZL_uDgppuYdbi4OtOU1ZrIG_J23LWaK6h2WAq9aKra41BqU4VLge9WLb4tRQxYOP6zrhhE4dlIZvJd13wKmKP4yjI8DKC47xQ_UwHnm2Yqyo8rMFp7_PFucunBjsAbYa2x21GBjHdpK0Lii7Bs2EjPrQhCFi-miO2Nn637fWdJeUu6WIfLF_tiQkLWS0iCybtvDPuiU_BOY_XOUW7e8QmR9B3s6_vq7w76w5MRlHCVWyyAclygunaT7dAWs_UXJvrs16v7hZZmSmd_FoNGKI5JPxWSvGHyVjNoYIbLCPzx5NvCk-zcu6pnYMHlT31Kz-_GpufKbvY31nbHxJ5lNxLicpBbKwkHujskO9ELzR0AkR6TAKF6h-ApH2K3LMCIEjh0wu72MxBVgavC2lRVtT6mkrRJECCJL3FDeQj3G__brdXl3jXVf7bnBFFf9FitwWWgknu0jbnZ9tWByP8b9efi51j1oRNaYihpzwdq-Bmx2MO4hm4VGUQaWnE5BpyQDraHG2gXGDtuVV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