llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.07k stars 11.99k forks source link

[clang] Assertion `ModuleScopes.size() <= 1 && "expected to be at global module scope"' failed. #115003

Open yijan4845 opened 1 week ago

yijan4845 commented 1 week ago

This testcase is generated by a fuzzer.

Compiler Explorer: https://godbolt.org/z/vKr6oPYrq

This invalid code will crash on Clang Assertion Trunk.

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
llvmbot commented 1 week ago

@llvm/issue-subscribers-clang-frontend

Author: Yihan Yang (yijan4845)

**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 ```
llvmbot commented 1 week ago

@llvm/issue-subscribers-c-20

Author: Yihan Yang (yijan4845)

**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 ```
shafik commented 1 week ago

CC @ChuanqiXu9