[clang][OpenMP] crashes on #pragma omp flatten
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
Reproducer:
https://godbolt.org/z/c4Y87j74q
```cpp
void foo () {
#pragma omp flatten
;
}
```
Backtrace:
```console
flatten
Unexpected directive
UNREACHABLE executed at /root/llvm-project/llvm/tools/clang/lib/Basic/OpenMPKinds.cpp:1018!
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. :3:5: current parser token ';'
2. :1:13: parsing function body 'foo'
3. :1:13: in compound statement ('{}')
#0 0x0000000004423f28 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4423f28)
#1 0x0000000004420dd4 llvm::sys::RunSignalHandlers() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4420dd4)
#2 0x000000000442140c llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x442140c)
#3 0x00000000043603c8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#4 0x0000765121045330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
#5 0x000076512109ec0c pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x9ec0c)
#6 0x000076512104527e raise (/lib/x86_64-linux-gnu/libc.so.6+0x4527e)
#7 0x00007651210288ff abort (/lib/x86_64-linux-gnu/libc.so.6+0x288ff)
#8 0x000000000436a73a (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x436a73a)
#9 0x000000000883a785 clang::getOpenMPCaptureRegions(llvm::SmallVectorImpl&, llvm::omp::Directive) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x883a785)
#10 0x000000000755f7b6 processCapturedRegions(clang::Sema&, llvm::omp::Directive, clang::Scope*, clang::SourceLocation) SemaOpenMP.cpp:0:0
#11 0x00000000075601af clang::SemaOpenMP::ActOnOpenMPRegionStart(llvm::omp::Directive, clang::Scope*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x75601af)
#12 0x0000000006e1d75e clang::Parser::ParseOpenMPExecutableDirective(clang::Parser::ParsedStmtContext, llvm::omp::Directive, clang::SourceLocation, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e1d75e)
#13 0x0000000006e28c45 clang::Parser::ParseOpenMPDeclarativeOrExecutableDirective(clang::Parser::ParsedStmtContext, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e28c45)
#14 0x0000000006e49a0c clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::ParsedAttributes&, clang::ParsedAttributes&, clang::LabelDecl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e49a0c)
#15 0x0000000006e4aed9 clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::LabelDecl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e4aed9)
#16 0x0000000006e533d5 clang::Parser::ParseCompoundStatementBody(bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e533d5)
#17 0x0000000006e53c1a clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e53c1a)
#18 0x0000000006d51c5d clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::LateParsedAttrList*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d51c5d)
#19 0x0000000006d9b7b6 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+++0x6d9b7b6)
#20 0x0000000006d460ab clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d460ab)
#21 0x0000000006d4688f clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d4688f)
#22 0x0000000006d53038 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d53038)
#23 0x0000000006d53f95 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d53f95)
#24 0x0000000006d54380 clang::Parser::ParseFirstTopLevelDecl(clang::OpaquePtr&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d54380)
#25 0x0000000006d3148e clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d3148e)
#26 0x0000000004f24ee8 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4f24ee8)
#27 0x0000000005252b28 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5252b28)
#28 0x00000000051df6ad clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x51df6ad)
#29 0x0000000005327dbd clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5327dbd)
#30 0x0000000000dab3bc cc1_main(llvm::ArrayRef, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdab3bc)
#31 0x0000000000da1fda ExecuteCC1Tool(llvm::SmallVectorImpl&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr) driver.cpp:0:0
#32 0x0000000000da215d int llvm::function_ref&)>::callback_fn&)>(long, llvm::SmallVectorImpl&) driver.cpp:0:0
#33 0x0000000004f9ce59 void llvm::function_ref::callback_fn>, std::__cxx11::basic_string, std::allocator>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#34 0x0000000004360804 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4360804)
#35 0x0000000004f9d9c5 clang::driver::CC1Command::Execute(llvm::ArrayRef>, std::__cxx11::basic_string, std::allocator>*, bool*) const (.part.0) Job.cpp:0:0
#36 0x0000000004f558a2 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4f558a2)
#37 0x0000000004f5a207 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4f5a207)
#38 0x0000000004f64775 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4f64775)
#39 0x0000000000da78ba clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xda78ba)
#40 0x0000000000cc35ba main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xcc35ba)
#41 0x000076512102a1ca (/lib/x86_64-linux-gnu/libc.so.6+0x2a1ca)
#42 0x000076512102a28b __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a28b)
#43 0x0000000000da1985 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xda1985)
clang++: error: clang frontend command failed due to signal (use -v to see invocation)
Compiler returned: 134
```
Contributor guide
Research direction
Start by compiling the reproducer with clang++ -fopenmp and inspect the OpenMP paths named in the backtrace: llvm/tools/clang/lib/Basic/OpenMPKinds.cpp around line 1018, SemaOpenMP.cpp, and Parser::ParseOpenMPExecutableDirective. Add a regression test for the shown pragma and verify that compilation reports a diagnostic instead of crashing.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 56/100