llvm / llvm/llvm-project

[clang][OpenMP] Assertion `!FD->getType().isNull() && "Expected a valid FunctionDecl"' failed.

Open
#210,261 2 comments 0 reactions 0 assignees View on GitHub
clang:frontend clang:openmp crash generated by fuzzer regression:20
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Reproducer:
https://godbolt.org/z/WcavTqrbq
```cpp
template void foo(Args... args) {
auto c = []() -> decltype(({
#pragma omp target parallel for
for (int i = 0; i < 2; i++)
;
})) {};
}
```

Backtrace:
```console
clang++: /root/llvm-project/llvm/tools/clang/lib/AST/Decl.cpp:6108: bool clang::IsArmStreamingFunction(const clang::FunctionDecl*, bool): Assertion `!FD->getType().isNull() && "Expected a valid FunctionDecl"' 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:5: current parser token 'for'
2. :1:52: parsing function body 'foo'
3. :1:52: in compound statement ('{}')
4. :2:12: lambda expression parsing
5. :2:30: in compound statement ('{}')
#0 0x00000000043f3668 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x43f3668)
#1 0x00000000043f0524 llvm::sys::RunSignalHandlers() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x43f0524)
#2 0x00000000043f0b4c llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x43f0b4c)
#3 0x000000000432fb88 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#4 0x000075ca92645330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
#5 0x000075ca9269eb2c pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x9eb2c)
#6 0x000075ca9264527e raise (/lib/x86_64-linux-gnu/libc.so.6+0x4527e)
#7 0x000075ca926288ff abort (/lib/x86_64-linux-gnu/libc.so.6+0x288ff)
#8 0x000075ca9262881b (/lib/x86_64-linux-gnu/libc.so.6+0x2881b)
#9 0x000075ca9263b517 (/lib/x86_64-linux-gnu/libc.so.6+0x3b517)
#10 0x0000000007f1ecd6 clang::IsArmStreamingFunction(clang::FunctionDecl const*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7f1ecd6)
#11 0x0000000007683dbf clang::Sema::ActOnCapturedRegionStart(clang::SourceLocation, clang::Scope*, clang::CapturedRegionKind, llvm::ArrayRef>, unsigned int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7683dbf)
#12 0x00000000074f625d processCapturedRegions(clang::Sema&, llvm::omp::Directive, clang::Scope*, clang::SourceLocation) SemaOpenMP.cpp:0:0
#13 0x00000000074f635f clang::SemaOpenMP::ActOnOpenMPRegionStart(llvm::omp::Directive, clang::Scope*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x74f635f)
#14 0x0000000006ddb516 clang::Parser::ParseOpenMPExecutableDirective(clang::Parser::ParsedStmtContext, llvm::omp::Directive, clang::SourceLocation, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6ddb516)
#15 0x0000000006de65b5 clang::Parser::ParseOpenMPDeclarativeOrExecutableDirective(clang::Parser::ParsedStmtContext, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6de65b5)
#16 0x0000000006e070f4 clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::ParsedAttributes&, clang::ParsedAttributes&, clang::LabelDecl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e070f4)
#17 0x0000000006e08959 clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::LabelDecl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e08959)
#18 0x0000000006e10dee clang::Parser::ParseCompoundStatementBody(bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e10dee)
#19 0x0000000006e11534 void llvm::function_ref::callback_fn(long) ParseStmt.cpp:0:0
#20 0x00000000087fec81 clang::StackExhaustionHandler::runWithSufficientStackSpace(clang::SourceLocation, llvm::function_ref) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x87fec81)
#21 0x0000000006e011da clang::Parser::ParseCompoundStatement(bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e011da)
#22 0x0000000006d895d9 clang::Parser::ParseParenExpression(clang::ParenParseOption&, bool, clang::ParenExprKind, clang::TypoCorrectionTypeBehavior, clang::OpaquePtr&, clang::SourceLocation&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d895d9)
#23 0x0000000006d7f7bd clang::Parser::ParseCastExpression(clang::CastParseKind, bool, bool&, clang::TypoCorrectionTypeBehavior, bool, bool*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d7f7bd)
#24 0x0000000006d80967 clang::Parser::ParseCastExpression(clang::CastParseKind, bool, clang::TypoCorrectionTypeBehavior, bool, bool*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d80967)
#25 0x0000000006d809f9 clang::Parser::ParseAssignmentExpression(clang::TypoCorrectionTypeBehavior) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d809f9)
#26 0x0000000006d852e9 clang::Parser::ParseExpression(clang::TypoCorrectionTypeBehavior) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d852e9)
#27 0x0000000006d60485 clang::Parser::ParseDecltypeSpecifier(clang::DeclSpec&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d60485)
#28 0x0000000006d9db52 clang::Parser::ParseOptionalCXXScopeSpecifier(clang::CXXScopeSpec&, clang::OpaquePtr, bool, bool, bool*, bool, clang::IdentifierInfo const**, bool, bool, bool, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d9db52)
#29 0x0000000006d06800 clang::Parser::TryAnnotateCXXScopeToken(bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d06800)
#30 0x0000000006d47e14 clang::Parser::ParseDeclarationSpecifiers(clang::DeclSpec&, clang::Parser::ParsedTemplateInfo&, clang::AccessSpecifier, clang::Parser::DeclSpecContext, clang::LateParsedAttrList*, clang::ImplicitTypenameContext) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d47e14)
#31 0x0000000006d49905 clang::Parser::ParseSpecifierQualifierList(clang::DeclSpec&, clang::ImplicitTypenameContext, clang::AccessSpecifier, clang::Parser::DeclSpecContext) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d49905)
#32 0x0000000006d49e05 clang::Parser::ParseTypeName(clang::SourceRange*, clang::DeclaratorContext, clang::AccessSpecifier, clang::Decl**, clang::ParsedAttributes*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d49e05)
#33 0x0000000006d9b3af clang::Parser::ParseLambdaExpressionAfterIntroducer(clang::LambdaIntroducer&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d9b3af)
#34 0x0000000006d9b7bb clang::Parser::ParseLambdaExpression() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d9b7bb)
#35 0x0000000006d7ffa5 clang::Parser::ParseCastExpression(clang::CastParseKind, bool, bool&, clang::TypoCorrectionTypeBehavior, bool, bool*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d7ffa5)
#36 0x0000000006d80967 clang::Parser::ParseCastExpression(clang::CastParseKind, bool, clang::TypoCorrectionTypeBehavior, bool, bool*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d80967)
#37 0x0000000006d809f9 clang::Parser::ParseAssignmentExpression(clang::TypoCorrectionTypeBehavior) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d809f9)
#38 0x0000000006daa290 clang::Parser::ParseInitializer(clang::Decl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6daa290)
#39 0x0000000006d385ff clang::Parser::ParseDeclarationAfterDeclaratorAndAttributes(clang::Declarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d385ff)
#40 0x0000000006d587f9 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+++0x6d587f9)
#41 0x0000000006d59c3f clang::Parser::ParseSimpleDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::ParsedAttributes&, bool, clang::Parser::ForRangeInit*, clang::SourceLocation*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d59c3f)
#42 0x0000000006d5a10c clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::ParsedAttributes&, clang::SourceLocation*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d5a10c)
#43 0x0000000006e080ad clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::ParsedAttributes&, clang::ParsedAttributes&, clang::LabelDecl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e080ad)
#44 0x0000000006e08959 clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::LabelDecl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e08959)
#45 0x0000000006e10dee clang::Parser::ParseCompoundStatementBody(bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e10dee)
#46 0x0000000006e1160a clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e1160a)
#47 0x0000000006d0f973 clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::LateParsedAttrList*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d0f973)
#48 0x0000000006d59266 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+++0x6d59266)
#49 0x0000000006e1d180 clang::Parser::ParseDeclarationAfterTemplate(clang::DeclaratorContext, clang::Parser::ParsedTemplateInfo&, clang::ParsingDeclRAIIObject&, clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e1d180)
#50 0x0000000006e297f3 clang::Parser::ParseTemplateDeclarationOrSpecialization(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier) (.part.0) ParseTemplate.cpp:0:0
#51 0x0000000006e29bea clang::Parser::ParseDeclarationStartingWithTemplate(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e29bea)
#52 0x0000000006d5a2b0 clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::ParsedAttributes&, clang::SourceLocation*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d5a2b0)
#53 0x0000000006d10df6 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d10df6)
#54 0x0000000006d11ce5 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d11ce5)
#55 0x0000000006d120d0 clang::Parser::ParseFirstTopLevelDecl(clang::OpaquePtr&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d120d0)
#56 0x0000000006ceebc3 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6ceebc3)
#57 0x0000000004ef1628 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4ef1628)
#58 0x000000000521ccc8 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x521ccc8)
#59 0x00000000051aa16d clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x51aa16d)
#60 0x00000000052f53fd clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x52f53fd)
#61 0x0000000000da6c9c cc1_main(llvm::ArrayRef, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xda6c9c)
#62 0x0000000000d9d8aa ExecuteCC1Tool(llvm::SmallVectorImpl&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr) driver.cpp:0:0
#63 0x0000000000d9da2d int llvm::function_ref&)>::callback_fn&)>(long, llvm::SmallVectorImpl&) driver.cpp:0:0
#64 0x0000000004f688f9 void llvm::function_ref::callback_fn>, std::__cxx11::basic_string, std::allocator>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#65 0x000000000432ffc4 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x432ffc4)
#66 0x0000000004f69465 clang::driver::CC1Command::Execute(llvm::ArrayRef>, std::__cxx11::basic_string, std::allocator>*, bool*) const (.part.0) Job.cpp:0:0
#67 0x0000000004f21e32 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4f21e32)
#68 0x0000000004f26667 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4f26667)
#69 0x0000000004f30bc5 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4f30bc5)
#70 0x0000000000da318a clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xda318a)
#71 0x0000000000cbef4a main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xcbef4a)
#72 0x000075ca9262a1ca (/lib/x86_64-linux-gnu/libc.so.6+0x2a1ca)
#73 0x000075ca9262a28b __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a28b)
#74 0x0000000000d9d255 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xd9d255)
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++ -fopenmp. Start with clang/lib/AST/Decl.cpp at IsArmStreamingFunction and follow the call from clang/lib/Sema/SemaOpenMP.cpp through ActOnCapturedRegionStart. Done means the reproducer no longer aborts with the invalid FunctionDecl assertion and has regression coverage.

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.