llvm / llvm/llvm-project

[clang][OpenMP] Assertion `!isa<TagDecl>(this)' failed.

Open
#213,666 3 comments 0 reactions 0 assignees View on GitHub
clang:frontend clang:openmp crash generated by fuzzer
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Reproducer:
https://godbolt.org/z/W8eqn6Khs
```cpp
enum omp_interop_t : long unsigned int {};

template void foo() {
T t;
#pragma omp interop init(target : t)
}

void bar(int *y) {
foo();
--y;
}
```

Backtrace:
```console
clang++: /root/llvm-project/llvm/tools/clang/include/clang/AST/Decl.h:3583: const clang::Type* clang::TypeDecl::getTypeForDecl() const: Assertion `!isa(this)' 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. parser at end of file
2. :3:28: instantiating function definition 'foo'
#0 0x000000000441d858 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x441d858)
#1 0x000000000441a704 llvm::sys::RunSignalHandlers() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x441a704)
#2 0x000000000441ad3c llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x441ad3c)
#3 0x0000000004359d18 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#4 0x00007b7f7b845330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
#5 0x00007b7f7b89eb2c pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x9eb2c)
#6 0x00007b7f7b84527e raise (/lib/x86_64-linux-gnu/libc.so.6+0x4527e)
#7 0x00007b7f7b8288ff abort (/lib/x86_64-linux-gnu/libc.so.6+0x288ff)
#8 0x00007b7f7b82881b (/lib/x86_64-linux-gnu/libc.so.6+0x2881b)
#9 0x00007b7f7b83b517 (/lib/x86_64-linux-gnu/libc.so.6+0x3b517)
#10 0x0000000007569982 isValidInteropVariable(clang::Sema&, clang::Expr*, clang::SourceLocation, llvm::omp::Clause) SemaOpenMP.cpp:0:0
#11 0x00000000075699e6 clang::SemaOpenMP::ActOnOpenMPInitClause(clang::Expr*, clang::OMPInteropInfo&, clang::SourceLocation, clang::SourceLocation, clang::SourceLocation, clang::SourceLocation) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x75699e6)
#12 0x00000000078d4ba2 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformOMPInitClause(clang::OMPInitClause*) SemaTemplateInstantiate.cpp:0:0
#13 0x0000000007911bf7 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformOMPExecutableDirective(clang::OMPExecutableDirective*) SemaTemplateInstantiate.cpp:0:0
#14 0x00000000079149a4 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformOMPInteropDirective(clang::OMPInteropDirective*) SemaTemplateInstantiate.cpp:0:0
#15 0x000000000790e6d5 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformCompoundStmt(clang::CompoundStmt*, bool) SemaTemplateInstantiate.cpp:0:0
#16 0x00000000079181ee clang::Sema::SubstStmt(clang::Stmt*, clang::MultiLevelTemplateArgumentList const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x79181ee)
#17 0x00000000079b69d5 clang::Sema::InstantiateFunctionDefinition(clang::SourceLocation, clang::FunctionDecl*, bool, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x79b69d5)
#18 0x00000000079b4bf6 clang::Sema::PerformPendingInstantiations(bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x79b4bf6)
#19 0x0000000006ee5942 clang::Sema::ActOnEndOfTranslationUnitFragment(clang::TUFragmentKind) (.part.0) Sema.cpp:0:0
#20 0x0000000006ee5c82 clang::Sema::ActOnEndOfTranslationUnit() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6ee5c82)
#21 0x0000000006d4688a clang::Parser::ParseTopLevelDecl(clang::OpaquePtr&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d4688a)
#22 0x0000000006d23c12 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d23c12)
#23 0x0000000004f20de8 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4f20de8)
#24 0x000000000524e948 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x524e948)
#25 0x00000000051db4cd clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x51db4cd)
#26 0x000000000532337d clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x532337d)
#27 0x0000000000da9a0c cc1_main(llvm::ArrayRef, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xda9a0c)
#28 0x0000000000da062a ExecuteCC1Tool(llvm::SmallVectorImpl&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr) driver.cpp:0:0
#29 0x0000000000da07ad int llvm::function_ref&)>::callback_fn&)>(long, llvm::SmallVectorImpl&) driver.cpp:0:0
#30 0x0000000004f98d49 void llvm::function_ref::callback_fn>, std::__cxx11::basic_string, std::allocator>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#31 0x000000000435a154 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x435a154)
#32 0x0000000004f998b5 clang::driver::CC1Command::Execute(llvm::ArrayRef>, std::__cxx11::basic_string, std::allocator>*, bool*) const (.part.0) Job.cpp:0:0
#33 0x0000000004f516d2 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4f516d2)
#34 0x0000000004f56037 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4f56037)
#35 0x0000000004f60705 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4f60705)
#36 0x0000000000da5f0a clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xda5f0a)
#37 0x0000000000cc1dea main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xcc1dea)
#38 0x00007b7f7b82a1ca (/lib/x86_64-linux-gnu/libc.so.6+0x2a1ca)
#39 0x00007b7f7b82a28b __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a28b)
#40 0x0000000000d9ffd5 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xd9ffd5)
clang++: error: clang frontend command failed due to signal (use -v to see invocation)
Compiler returned: 134
```

Contributor guide

Open the contributing guide

Research direction

Reproduce the assertion with the linked Compiler Explorer example using clang++ and OpenMP. Start in isValidInteropVariable in SemaOpenMP.cpp, then follow the template-instantiation path through SemaTemplateInstantiate.cpp; add regression coverage for the reproducer and verify compilation no longer aborts.

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
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.