Issue 154534
Summary [clang][OpenMP] Assertion `isa<ObjCMethodDecl>(DC) && "unexpected parent code decl"' failed.
Labels crash, clang:openmp
Assignees
Reporter k-arrows
    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
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to