[clang][OpenMP] Assertion `(SemaRef.CurContext->isDependentContext() || B.builtAll()) && "loop exprs were not built"' failed.
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
Reproducer:
https://godbolt.org/z/454Kcbqaq
```cpp
template &T::foo() {
#pragma omp simd collapse(N)
;
}
```
Backtrace:
```console
clang++: /root/llvm-project/llvm/tools/clang/lib/Sema/SemaOpenMP.cpp:3099: bool finishLinearClauses(clang::Sema&, llvm::ArrayRef, clang::OMPLoopBasedDirective::HelperExprs&, {anonymous}::DSAStackTy*): Assertion `(SemaRef.CurContext->isDependentContext() || B.builtAll()) && "loop exprs were not built"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and dumped files.
Stack dump:
0. Program arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/clang++ -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 -fopenmp
1. :4:1: current parser token '}'
2. :1:37: parsing function body
3. :1:37: in compound statement ('{}')
#0 0x0000000004419288 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4419288)
#1 0x0000000004416134 llvm::sys::RunSignalHandlers() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4416134)
#2 0x000000000441676c llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x441676c)
#3 0x0000000004354378 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#4 0x0000710a3fe45330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
#5 0x0000710a3fe9ec0c pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x9ec0c)
#6 0x0000710a3fe4527e raise (/lib/x86_64-linux-gnu/libc.so.6+0x4527e)
#7 0x0000710a3fe288ff abort (/lib/x86_64-linux-gnu/libc.so.6+0x288ff)
#8 0x0000710a3fe2881b (/lib/x86_64-linux-gnu/libc.so.6+0x2881b)
#9 0x0000710a3fe3b517 (/lib/x86_64-linux-gnu/libc.so.6+0x3b517)
#10 0x00000000075ed8f7 finishLinearClauses(clang::Sema&, llvm::ArrayRef, clang::OMPLoopBasedDirective::HelperExprs&, (anonymous namespace)::DSAStackTy*) SemaOpenMP.cpp:0:0
#11 0x00000000075f075b clang::SemaOpenMP::ActOnOpenMPSimdDirective(llvm::ArrayRef, clang::Stmt*, clang::SourceLocation, clang::SourceLocation, llvm::SmallDenseMap, llvm::detail::DenseMapPair>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x75f075b)
#12 0x0000000007612bf3 clang::SemaOpenMP::ActOnOpenMPExecutableDirective(llvm::omp::Directive, clang::DeclarationNameInfo const&, llvm::omp::Directive, llvm::ArrayRef, clang::Stmt*, clang::SourceLocation, clang::SourceLocation) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7612bf3)
#13 0x0000000006e43392 clang::Parser::ParseOpenMPExecutableDirective(clang::Parser::ParsedStmtContext, llvm::omp::Directive, clang::SourceLocation, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e43392)
#14 0x0000000006e4f335 clang::Parser::ParseOpenMPDeclarativeOrExecutableDirective(clang::Parser::ParsedStmtContext, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e4f335)
#15 0x0000000006e7031c clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::ParsedAttributes&, clang::ParsedAttributes&, clang::LabelDecl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e7031c)
#16 0x0000000006e71809 clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::LabelDecl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e71809)
#17 0x0000000006e79d25 clang::Parser::ParseCompoundStatementBody(bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e79d25)
#18 0x0000000006e7a56a clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e7a56a)
#19 0x0000000006d7703d clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::LateParsedAttrList*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d7703d)
#20 0x0000000006dc0a96 clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::Parser::ParsedTemplateInfo&, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6dc0a96)
#21 0x0000000006e860f0 clang::Parser::ParseDeclarationAfterTemplate(clang::DeclaratorContext, clang::Parser::ParsedTemplateInfo&, clang::ParsingDeclRAIIObject&, clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e860f0)
#22 0x0000000006e92783 clang::Parser::ParseTemplateDeclarationOrSpecialization(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier) (.part.0) ParseTemplate.cpp:0:0
#23 0x0000000006e92b7a clang::Parser::ParseDeclarationStartingWithTemplate(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e92b7a)
#24 0x0000000006dc1ae0 clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::ParsedAttributes&, clang::SourceLocation*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6dc1ae0)
#25 0x0000000006d78450 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d78450)
#26 0x0000000006d79365 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d79365)
#27 0x0000000006d79750 clang::Parser::ParseFirstTopLevelDecl(clang::OpaquePtr&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d79750)
#28 0x0000000006d55efc clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d55efc)
#29 0x0000000004f28c28 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4f28c28)
#30 0x00000000052558c8 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x52558c8)
#31 0x00000000051e34cd clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x51e34cd)
#32 0x000000000532b05d clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x532b05d)
#33 0x0000000000d91bfc cc1_main(llvm::ArrayRef, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xd91bfc)
#34 0x0000000000d888fa ExecuteCC1Tool(llvm::SmallVectorImpl&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr) driver.cpp:0:0
#35 0x0000000000d88a7d int llvm::function_ref&)>::callback_fn&)>(long, llvm::SmallVectorImpl&) driver.cpp:0:0
#36 0x0000000004fa15c9 void llvm::function_ref::callback_fn>, std::__cxx11::basic_string, std::allocator>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#37 0x00000000043547b4 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x43547b4)
#38 0x0000000004fa2135 clang::driver::CC1Command::Execute(llvm::ArrayRef>, std::__cxx11::basic_string, std::allocator>*, bool*) const (.part.0) Job.cpp:0:0
#39 0x0000000004f59fa2 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4f59fa2)
#40 0x0000000004f5e907 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4f5e907)
#41 0x0000000004f68ef5 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4f68ef5)
#42 0x0000000000d8e0ea clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xd8e0ea)
#43 0x0000000000ccc1ea main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xccc1ea)
#44 0x0000710a3fe2a1ca (/lib/x86_64-linux-gnu/libc.so.6+0x2a1ca)
#45 0x0000710a3fe2a28b __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a28b)
#46 0x0000000000d882a5 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xd882a5)
clang++: error: clang frontend command failed due to signal (use -v to see invocation)
Compiler returned: 134
```
Contributor guide
Research direction
Reproduce the assertion with the Godbolt example using Clang and -fopenmp, then inspect finishLinearClauses in clang/lib/Sema/SemaOpenMP.cpp and its caller ActOnOpenMPSimdDirective. Trace the templated OpenMP simd path and add a regression test for the reproducer; done means the input no longer aborts with the "loop exprs were not built" assertion.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100