llvm / llvm/llvm-project

[clang][OpenMP] Assertion `CSI && "Failed to find CapturedRegionScopeInfo"' failed.

Open
#223,397 2 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/qnWrjc95s
```cpp
int &foo = []() {
#pragma omp target
foo(42);
};
```

Backtrace:
```console
clang++: /root/llvm-project/llvm/tools/clang/lib/Sema/SemaOpenMP.cpp:2476: clang::VarDecl* clang::SemaOpenMP::isOpenMPCapturedDecl(clang::ValueDecl*, bool, unsigned int): Assertion `CSI && "Failed to find CapturedRegionScopeInfo"' 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:12: lambda expression parsing
3. :1:17: in compound statement ('{}')
#0 0x00000000044b9718 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x44b9718)
#1 0x00000000044b6974 llvm::sys::RunSignalHandlers() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x44b6974)
#2 0x00000000044b6fac llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x44b6fac)
#3 0x00000000043f35c8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#4 0x000075cc6b045330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
#5 0x000075cc6b09ec0c pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x9ec0c)
#6 0x000075cc6b04527e raise (/lib/x86_64-linux-gnu/libc.so.6+0x4527e)
#7 0x000075cc6b0288ff abort (/lib/x86_64-linux-gnu/libc.so.6+0x288ff)
#8 0x000075cc6b02881b (/lib/x86_64-linux-gnu/libc.so.6+0x2881b)
#9 0x000075cc6b03b517 (/lib/x86_64-linux-gnu/libc.so.6+0x3b517)
#10 0x0000000007675db0 clang::SemaOpenMP::isOpenMPCapturedDecl(clang::ValueDecl*, bool, unsigned int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7675db0)
#11 0x0000000007367757 clang::Sema::getNonOdrUseReasonInCurrentContext(clang::ValueDecl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7367757)
#12 0x00000000073b7cb1 clang::Sema::BuildDeclRefExpr(clang::ValueDecl*, clang::QualType, clang::ExprValueKind, clang::DeclarationNameInfo const&, clang::NestedNameSpecifierLoc, clang::NamedDecl*, clang::SourceLocation, clang::TemplateArgumentListInfo const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x73b7cb1)
#13 0x00000000073b844f clang::Sema::BuildDeclRefExpr(clang::ValueDecl*, clang::QualType, clang::ExprValueKind, clang::DeclarationNameInfo const&, clang::CXXScopeSpec const*, clang::NamedDecl*, clang::SourceLocation, clang::TemplateArgumentListInfo const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x73b844f)
#14 0x00000000073bdccb clang::Sema::BuildDeclarationNameExpr(clang::CXXScopeSpec const&, clang::DeclarationNameInfo const&, clang::NamedDecl*, clang::NamedDecl*, clang::TemplateArgumentListInfo const*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x73bdccb)
#15 0x00000000075534d7 clang::Sema::BuildCaptureInit(clang::sema::Capture const&, clang::SourceLocation, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x75534d7)
#16 0x00000000077cf926 clang::Sema::ActOnCapturedRegionEnd(clang::Stmt*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x77cf926)
#17 0x0000000007661867 clang::SemaOpenMP::ActOnOpenMPRegionEnd(clang::ActionResult, llvm::ArrayRef) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7661867)
#18 0x0000000006efb10b clang::Parser::ParseOpenMPExecutableDirective(clang::Parser::ParsedStmtContext, llvm::omp::Directive, clang::SourceLocation, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6efb10b)
#19 0x0000000006f06586 clang::Parser::ParseOpenMPDeclarativeOrExecutableDirective(clang::Parser::ParsedStmtContext, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6f06586)
#20 0x0000000006f2760c clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::ParsedAttributes&, clang::ParsedAttributes&, clang::LabelDecl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6f2760c)
#21 0x0000000006f28af6 clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::LabelDecl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6f28af6)
#22 0x0000000006f3107e clang::Parser::ParseCompoundStatementBody(bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6f3107e)
#23 0x0000000006eb8b92 clang::Parser::ParseLambdaExpressionAfterIntroducer(clang::LambdaIntroducer&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6eb8b92)
#24 0x0000000006eb9c8b clang::Parser::ParseLambdaExpression() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6eb9c8b)
#25 0x0000000006e9ed55 clang::Parser::ParseCastExpression(clang::CastParseKind, bool, bool&, clang::TypoCorrectionTypeBehavior, bool, bool*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e9ed55)
#26 0x0000000006e9f657 clang::Parser::ParseCastExpression(clang::CastParseKind, bool, clang::TypoCorrectionTypeBehavior, bool, bool*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e9f657)
#27 0x0000000006e9f6e9 clang::Parser::ParseAssignmentExpression(clang::TypoCorrectionTypeBehavior) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e9f6e9)
#28 0x0000000006ec89b0 clang::Parser::ParseInitializer(clang::Decl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6ec89b0)
#29 0x0000000006e5707e clang::Parser::ParseDeclarationAfterDeclaratorAndAttributes(clang::Declarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e5707e)
#30 0x0000000006e77089 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+++0x6e77089)
#31 0x0000000006e2219b clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e2219b)
#32 0x0000000006e2298f clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e2298f)
#33 0x0000000006e2f3f8 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e2f3f8)
#34 0x0000000006e30335 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e30335)
#35 0x0000000006e30720 clang::Parser::ParseFirstTopLevelDecl(clang::OpaquePtr&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e30720)
#36 0x0000000006e0c7fc clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e0c7fc)
#37 0x0000000004fcee98 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4fcee98)
#38 0x00000000052efb78 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x52efb78)
#39 0x000000000527d78d clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x527d78d)
#40 0x00000000053c439d clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x53c439d)
#41 0x0000000000d9173c cc1_main(llvm::ArrayRef, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xd9173c)
#42 0x0000000000d8845a ExecuteCC1Tool(llvm::SmallVectorImpl&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr) driver.cpp:0:0
#43 0x0000000000d885dd int llvm::function_ref&)>::callback_fn&)>(long, llvm::SmallVectorImpl&) driver.cpp:0:0
#44 0x0000000005043169 void llvm::function_ref::callback_fn>, std::__cxx11::basic_string, std::allocator>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#45 0x00000000043f39c4 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x43f39c4)
#46 0x0000000005043cd5 clang::driver::CC1Command::Execute(llvm::ArrayRef>, std::__cxx11::basic_string, std::allocator>*, bool*) const (.part.0) Job.cpp:0:0
#47 0x0000000005002102 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5002102)
#48 0x0000000005006a67 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5006a67)
#49 0x0000000005010fc5 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5010fc5)
#50 0x0000000000d8dc4a clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xd8dc4a)
#51 0x0000000000ccb5ea main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xccb5ea)
#52 0x000075cc6b02a1ca (/lib/x86_64-linux-gnu/libc.so.6+0x2a1ca)
#53 0x000075cc6b02a28b __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a28b)
#54 0x0000000000d87e05 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xd87e05)
clang++: error: clang frontend command failed due to signal (use -v to see invocation)
Program terminated with signal SIGABRT (6)
Compiler returned: 134
```

Contributor guide

Open the contributing guide

Research direction

Reproduce the crash with the Compiler Explorer example and inspect clang/lib/Sema/SemaOpenMP.cpp around line 2476, following the SemaOpenMP::isOpenMPCapturedDecl call in the backtrace. Trace how the lambda and OpenMP captured-region state are handled; done means the reproducer no longer triggers the assertion and the regression is covered by an appropriate test.

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.