<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/154534>154534</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang][OpenMP] Assertion `isa<ObjCMethodDecl>(DC) && "unexpected parent code decl"' failed.
</td>
</tr>
<tr>
<th>Labels</th>
<td>
crash,
clang:openmp
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
k-arrows
</td>
</tr>
</table>
<pre>
Reproducer:
https://godbolt.org/z/Eof85ovnn
```cpp
struct S {
int t;
S();
~S();
template <int N>
void foo() {
#pragma omp parallel default(firstprivate)
{
[=]() -> int {
return t;
}();
}
}
};
void bar() {
S s;
s.foo<42>();
}
```
Backtrace:
```console
clang++: /root/llvm-project/llvm/tools/clang/lib/CodeGen/CGDecl.cpp:336: llvm::Constant* clang::CodeGen::CodeGenModule::getOrCreateStaticVarDecl(const clang::VarDecl&, llvm::GlobalValue::LinkageTypes): Assertion `isa<ObjCMethodDecl>(DC) && "unexpected parent code decl"' 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++ -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 <source>
1. <eof> parser at end of file
2. Per-file LLVM IR generation
3. <source>:7:8: Generating code for declaration 'S::foo'
#0 0x0000000004038188 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4038188)
#1 0x00000000040355b4 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x40355b4)
#2 0x0000000003f79e28 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#3 0x0000770eacc42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#4 0x0000770eacc969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
#5 0x0000770eacc42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
#6 0x0000770eacc287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
#7 0x0000770eacc2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
#8 0x0000770eacc39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#9 0x00000000049319b7 clang::CodeGen::CodeGenModule::getOrCreateStaticVarDecl(clang::VarDecl const&, llvm::GlobalValue::LinkageTypes) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x49319b7)
#10 0x0000000004931faa clang::CodeGen::CodeGenFunction::EmitStaticVarDecl(clang::VarDecl const&, llvm::GlobalValue::LinkageTypes) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4931faa)
#11 0x000000000493a11b clang::CodeGen::CodeGenFunction::EmitVarDecl(clang::VarDecl const&) (.part.0) CGDecl.cpp:0:0
#12 0x00000000045313b3 (anonymous namespace)::OMPLexicalScope::OMPLexicalScope(clang::CodeGen::CodeGenFunction&, clang::OMPExecutableDirective const&, std::optional<llvm::omp::Directive>, bool) CGStmtOpenMP.cpp:0:0
#13 0x000000000453add7 emitCommonOMPParallelDirective(clang::CodeGen::CodeGenFunction&, clang::OMPExecutableDirective const&, llvm::omp::Directive, clang::CodeGen::RegionCodeGenTy const&, llvm::function_ref<void (clang::CodeGen::CodeGenFunction&, clang::OMPExecutableDirective const&, llvm::SmallVectorImpl<llvm::Value*>&)> const&) CGStmtOpenMP.cpp:0:0
#14 0x000000000455963a clang::CodeGen::CodeGenFunction::EmitOMPParallelDirective(clang::OMPParallelDirective const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x455963a)
#15 0x000000000450df8b clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x450df8b)
#16 0x0000000004515d0c clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4515d0c)
#17 0x000000000457d16e clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::Stmt const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x457d16e)
#18 0x000000000458edb4 clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x458edb4)
#19 0x00000000045fa0dd clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x45fa0dd)
#20 0x00000000045f5074 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x45f5074)
#21 0x0000000004601a2c clang::CodeGen::CodeGenModule::EmitDeferred() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4601a2c)
#22 0x0000000004601948 clang::CodeGen::CodeGenModule::EmitDeferred() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4601948)
#23 0x0000000004603fb3 clang::CodeGen::CodeGenModule::Release() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4603fb3)
#24 0x00000000049e004e (anonymous namespace)::CodeGeneratorImpl::HandleTranslationUnit(clang::ASTContext&) ModuleBuilder.cpp:0:0
#25 0x00000000049dc255 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x49dc255)
#26 0x00000000066ed82c clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x66ed82c)
#27 0x00000000049dc9e8 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x49dc9e8)
#28 0x0000000004cd15a5 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4cd15a5)
#29 0x0000000004c4d74e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4c4d74e)
#30 0x0000000004dc30b1 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4dc30b1)
#31 0x0000000000db1a9f cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdb1a9f)
#32 0x0000000000da874a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#33 0x0000000004a449c9 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
#34 0x0000000003f7a2c4 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3f7a2c4)
#35 0x0000000004a44fdf 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
#36 0x0000000004a06c9d clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4a06c9d)
#37 0x0000000004a07d2e 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+++0x4a07d2e)
#38 0x0000000004a0f965 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4a0f965)
#39 0x0000000000dadf55 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdadf55)
#40 0x0000000000c61ba4 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xc61ba4)
#41 0x0000770eacc29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#42 0x0000770eacc29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#43 0x0000000000da81f5 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xda81f5)
clang++: error: clang frontend command failed with exit code 134 (use -v to see invocation)
Compiler returned: 134
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzkWl9zozj2_TTKi8ouEH8MD3kgOO5fT3V-SbWzvY8uIQmHCUiUJDLOPuxn35KEgyFO0u6Ku2ZrpzIzRkhX55x7dXUBYaWqLWfsEkRXIFpe4E4_CHn5OMNSir_URSHo8-V31kpBO8IkCDLgZQ9at8r8RCuAVltBC1HruZBbgFb_Amh1LcokEk-cAy8Dsef-SNsCL1NadkTDNQSLK-BlEFZcQw0Cd7EGKAEo3V_-e3RtmzRr2hprBkGQm6H_D4Jre-NJVBSWQrgRvXmAglbibYOhaFrYYonrmtWQshJ3tQYoKSupdCurJ6yZmchYgi_Y7O_oCgRLEC17wzMQXFvQfSfJdCf5QMGNX46JuCbzy_3f_HfPyQIvsBwBh3ANVT9azQ2tIA-R4XooiLO1F9iZu8LkUUtMmHPVIL_gStQMeBmpMd8CdGX-ggwCtJJCaIBWdf3UzFop_mRkfwnQSgtRK4BW_bBVXRUArXJB2RfGza8vS0bquXFvkAV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