Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clang++ segment fault in clang::Sema::ActOnCapScopeReturnStmt #48527

Closed
llvmbot opened this issue Feb 15, 2021 · 10 comments · Fixed by #66643
Closed

clang++ segment fault in clang::Sema::ActOnCapScopeReturnStmt #48527

llvmbot opened this issue Feb 15, 2021 · 10 comments · Fixed by #66643
Assignees
Labels
bugzilla Issues migrated from bugzilla c++ clang:frontend Language frontend issues, e.g. anything involving "Sema" confirmed Verified by a second party crash Prefer [crash-on-valid] or [crash-on-invalid] good first issue https://github.com/llvm/llvm-project/contribute

Comments

@llvmbot
Copy link
Member

llvmbot commented Feb 15, 2021

Bugzilla Link 49183
Version trunk
OS Linux
Reporter LLVM Bugzilla Contributor
CC @DougGregor,@fhahn,@zygoloid

Extended Description

The frontend fault blocks many downstream applications of clang (e.g., creduce).

Version 11.0.0 and 6.0.0 are affected.

int main() {
    auto a = [](void)__attribute__((b(({
    return 0;
}
$ cat /tmp/test-7c00f2.sh
# Crash reproducer for clang version 11.1.0 (https://github.com/llvm/llvm-project.git 1fdec59bffc11ae37eb51a1b9869f0696bfd5312)
# Driver args: "--driver-mode=g++" "test.cc"
# Original command:  "/data/xxx/git/llvm-project/build/bin/clang-11" "-cc1" "-triple" "x86_64-unknown-linux-gnu" "-emit-obj" "-mrelax-all" "-disable-free" "-main-file-name" "test.cc" "-mrelocation-model" "static" "-mframe-pointer=all" "-fmath-errno" "-fno-rounding-math" "-mconstructor-aliases" "-munwind-tables" "-target-cpu" "x86-64" "-fno-split-dwarf-inlining" "-debugger-tuning=gdb" "-resource-dir" "/data/xxx/git/llvm-project/build/lib/clang/11.1.0" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/x86_64-linux-gnu/c++/7.5.0" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/x86_64-linux-gnu/c++/7.5.0" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/backward" "-internal-isystem" "/usr/local/include" "-internal-isystem" "/data/xxx/git/llvm-project/build/lib/clang/11.1.0/include" "-internal-externc-isystem" "/usr/include/x86_64-linux-gnu" "-internal-externc-isystem" "/include" "-internal-externc-isystem" "/usr/include" "-fdeprecated-macro" "-fdebug-compilation-dir" "/data/xxx/docker_share/clang" "-ferror-limit" "19" "-fgnuc-version=4.2.1" "-fcxx-exceptions" "-fexceptions" "-fcolor-diagnostics" "-faddrsig" "-o" "/tmp/test-f61719.o" "-x" "c++" "test.cc"
 "/data/xxx/git/llvm-project/build/bin/clang-11" "-cc1" "-triple" "x86_64-unknown-linux-gnu" "-emit-obj" "-mrelax-all" "-disable-free" "-main-file-name" "test.cc" "-mrelocation-model" "static" "-mframe-pointer=all" "-fmath-errno" "-fno-rounding-math" "-mconstructor-aliases" "-munwind-tables" "-target-cpu" "x86-64" "-fno-split-dwarf-inlining" "-debugger-tuning=gdb" "-fdeprecated-macro" "-ferror-limit" "19" "-fgnuc-version=4.2.1" "-fcxx-exceptions" "-fexceptions" "-fcolor-diagnostics" "-faddrsig" "-x" "c++" "test-7c00f2.cpp"

$ ./clang++ test.cc
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.      Program arguments: /data/xxx/git/llvm-project/build/bin/clang-11 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -mrelax-all -disable-free -main-file-name test.cc -mrelocation-model static -mframe-pointer=all -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /data/xxx/git/llvm-project/build/lib/clang/11.1.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/x86_64-linux-gnu/c++/7.5.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/x86_64-linux-gnu/c++/7.5.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/backward -internal-isystem /usr/local/include -internal-isystem /data/xxx/git/llvm-project/build/lib/clang/11.1.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdeprecated-macro -fdebug-compilation-dir /data/xxx/docker_share/clang -ferror-limit 19 -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -faddrsig -o /tmp/test-bc1970.o -x c++ test.cc
1.      test.cc:3:13: current parser token ';'
2.      test.cc:1:12: parsing function body 'main'
3.      test.cc:1:12: in compound statement ('{}')
4.      test.cc:2:14: lambda expression parsing
5.      test.cc:2:40: in compound statement ('{}')
 #​0 0x0000000006e97306 llvm::sys::PrintStackTrace(llvm::raw_ostream&) /home/xxx/data/git/llvm-project/llvm/lib/Support/Unix/Signals.inc:560:7
 #​1 0x0000000006e9266e llvm::sys::RunSignalHandlers() /home/xxx/data/git/llvm-project/llvm/lib/Support/Signals.cpp:69:18
 #​2 0x0000000006e97caa SignalHandler(int) /home/xxx/data/git/llvm-project/llvm/lib/Support/Unix/Signals.inc:396:3
 #​3 0x00007f0e755278a0 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x128a0)
 #&#8203;4 0x00000000075bcc95 llvm::PointerIntPair<void*, 1u, int, llvm::pointer_union_detail::PointerUnionUIntTraits<clang::TypeSourceInfo*, clang::DeclaratorDecl::ExtInfo*>, llvm::PointerIntPairInfo<void*, 1u, llvm::pointer_union_detail::PointerUnionUIntTraits<clang::TypeSourceInfo*, clang::DeclaratorDecl::ExtInfo*> > >::getInt() const /home/xxx/data/git/llvm-project/llvm/include/llvm/ADT/PointerIntPair.h:61:57
 #&#8203;5 0x00000000075bcc95 bool llvm::PointerUnion<clang::TypeSourceInfo*, clang::DeclaratorDecl::ExtInfo*>::is<clang::DeclaratorDecl::ExtInfo*>() const /home/xxx/data/git/llvm-project/llvm/include/llvm/ADT/PointerUnion.h:188:0
 #&#8203;6 0x00000000075bcc95 clang::DeclaratorDecl::hasExtInfo() const /home/xxx/data/git/llvm-project/clang/include/clang/AST/Decl.h:686:0
 #&#8203;7 0x00000000075bcc95 clang::DeclaratorDecl::getTypeSourceInfo() const /home/xxx/data/git/llvm-project/clang/include/clang/AST/Decl.h:701:0
 #&#8203;8 0x000000000df02e89 clang::TypeSourceInfo::getType() const /home/xxx/data/git/llvm-project/clang/include/clang/AST/Type.h:0:0
 #&#8203;9 0x000000000df02e89 hasDeducedReturnType(clang::FunctionDecl*) /home/xxx/data/git/llvm-project/clang/lib/Sema/SemaStmt.cpp:3261:0
#&#8203;10 0x000000000df02e89 clang::Sema::ActOnCapScopeReturnStmt(clang::SourceLocation, clang::Expr*) /home/xxx/data/git/llvm-project/clang/lib/Sema/SemaStmt.cpp:3276:0
#&#8203;11 0x000000000df10e3a clang::Sema::BuildReturnStmt(clang::SourceLocation, clang::Expr*) /home/xxx/data/git/llvm-project/clang/lib/Sema/SemaStmt.cpp:3616:12
#&#8203;12 0x000000000df1077c clang::ActionResult<clang::Stmt*, true>::isInvalid() const /home/xxx/data/git/llvm-project/clang/include/clang/Sema/Ownership.h:0:0
#&#8203;13 0x000000000df1077c clang::Sema::ActOnReturnStmt(clang::SourceLocation, clang::Expr*, clang::Scope*) /home/xxx/data/git/llvm-project/clang/lib/Sema/SemaStmt.cpp:3594:0
#&#8203;14 0x000000000ca17cba clang::Parser::ParseReturnStatement() /home/xxx/data/git/llvm-project/clang/lib/Parse/ParseStmt.cpp:0:18
#&#8203;15 0x000000000ca09527 clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::Parser::ParsedAttributesWithRange&) /home/xxx/data/git/llvm-project/clang/lib/Parse/ParseStmt.cpp:282:11
#&#8203;16 0x000000000ca081a6 clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*) /home/xxx/data/git/llvm-project/clang/lib/Parse/ParseStmt.cpp:106:20
#&#8203;17 0x000000000ca1c77e clang::Parser::ParseCompoundStatementBody(bool) /home/xxx/data/git/llvm-project/clang/lib/Parse/ParseStmt.cpp:1089:11
#&#8203;18 0x000000000ca1a464 clang::Parser::ParseScope::~ParseScope() /home/xxx/data/git/llvm-project/clang/include/clang/Parse/Parser.h:0:0
#&#8203;19 0x000000000ca1a464 clang::Parser::ParseCompoundStatement(bool, unsigned int) /home/xxx/data/git/llvm-project/clang/lib/Parse/ParseStmt.cpp:904:0
#&#8203;20 0x000000000c91556d clang::Parser::ParseParenExpression(clang::Parser::ParenParseOption&, bool, bool, clang::OpaquePtr<clang::QualType>&, clang::SourceLocation&) /home/xxx/data/git/llvm-project/clang/lib/Parse/ParseExpr.cpp:2872:16
#&#8203;21 0x000000000c90fc2e clang::Parser::ParseCastExpression(clang::Parser::CastParseKind, bool, bool&, clang::Parser::TypeCastState, bool, bool*) /home/xxx/data/git/llvm-project/clang/lib/Parse/ParseExpr.cpp:957:11
#&#8203;22 0x000000000c902c60 clang::Parser::ParseCastExpression(clang::Parser::CastParseKind, bool, clang::Parser::TypeCastState, bool, bool*) /home/xxx/data/git/llvm-project/clang/lib/Parse/ParseExpr.cpp:681:20
#&#8203;23 0x000000000c8fe5ef clang::Parser::ParseAssignmentExpression(clang::Parser::TypeCastState) /home/xxx/data/git/llvm-project/clang/lib/Parse/ParseExpr.cpp:176:10
#&#8203;24 0x000000000c8627aa _ZN4llvm12function_refIFN5clang12ActionResultIPNS1_4ExprELb1EEES4_EEC2IZNS1_4Sema25CorrectDelayedTyposInExprES5_PNS1_7VarDeclEbS7_Ed_UlS4_E_EEOT_PNSt9enable_ifIXntsr3std7is_sameINSt9remove_cvINSt16remove_referenceISD_E4typeEE4typeES7_EE5valueEvE4typeE /home/xxx/data/git/llvm-project/llvm/include/llvm/ADT/STLExtras.h:0:0
#&#8203;25 0x000000000c8627aa clang::Parser::ParseAttributeArgsCommon(clang::IdentifierInfo*, clang::SourceLocation, clang::ParsedAttributes&, clang::SourceLocation*, clang::IdentifierInfo*, clang::SourceLocation, clang::AttributeCommonInfo::Syntax) /home/xxx/data/git/llvm-project/clang/lib/Parse/ParseDecl.cpp:397:0
#&#8203;26 0x000000000c86049b clang::Parser::ParseGNUAttributeArgs(clang::IdentifierInfo*, clang::SourceLocation, clang::ParsedAttributes&, clang::SourceLocation*, clang::IdentifierInfo*, clang::SourceLocation, clang::AttributeCommonInfo::Syntax, clang::Declarator*) /home/xxx/data/git/llvm-project/clang/lib/Parse/ParseDecl.cpp:480:3
#&#8203;27 0x000000000c85ed4a clang::Parser::ParseGNUAttributes(clang::ParsedAttributes&, clang::SourceLocation*, clang::Parser::LateParsedAttrList*, clang::Declarator*) /home/xxx/data/git/llvm-project/clang/lib/Parse/ParseDecl.cpp:189:9
#&#8203;28 0x000000000c93d177 clang::Parser::MaybeParseGNUAttributes(clang::ParsedAttributes&, clang::SourceLocation*, clang::Parser::LateParsedAttrList*) /home/xxx/data/git/llvm-project/clang/include/clang/Parse/Parser.h:2658:3
#&#8203;29 0x000000000c93d177 clang::Parser::ParseLambdaExpressionAfterIntroducer(clang::LambdaIntroducer&) /home/xxx/data/git/llvm-project/clang/lib/Parse/ParseExprCXX.cpp:1322:0
#&#8203;30 0x000000000c939030 clang::Parser::ParseLambdaExpression() /home/xxx/data/git/llvm-project/clang/lib/Parse/ParseExprCXX.cpp:739:10
#&#8203;31 0x000000000c90f457 clang::Parser::ParseCastExpression(clang::Parser::CastParseKind, bool, bool&, clang::Parser::TypeCastState, bool, bool*) /home/xxx/data/git/llvm-project/clang/lib/Parse/ParseExpr.cpp:1764:13
#&#8203;32 0x000000000c902c60 clang::Parser::ParseCastExpression(clang::Parser::CastParseKind, bool, clang::Parser::TypeCastState, bool, bool*) /home/xxx/data/git/llvm-project/clang/lib/Parse/ParseExpr.cpp:681:20
#&#8203;33 0x000000000c8fe5ef clang::Parser::ParseAssignmentExpression(clang::Parser::TypeCastState) /home/xxx/data/git/llvm-project/clang/lib/Parse/ParseExpr.cpp:176:10
#&#8203;34 0x000000000c885bb1 clang::Parser::ParseInitializer() /home/xxx/data/git/llvm-project/clang/include/clang/Parse/Parser.h:0:14
#&#8203;35 0x000000000c885bb1 clang::Parser::ParseDeclarationAfterDeclaratorAndAttributes(clang::Declarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::ForRangeInit*) /home/xxx/data/git/llvm-project/clang/lib/Parse/ParseDecl.cpp:2232:0
#&#8203;36 0x000000000c880fc7 clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::SourceLocation*, clang::Parser::ForRangeInit*) /home/xxx/data/git/llvm-project/clang/lib/Parse/ParseDecl.cpp:1986:9
#&#8203;37 0x000000000c8739fc clang::Parser::ParseSimpleDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::Parser::ParsedAttributesWithRange&, bool, clang::Parser::ForRangeInit*, clang::SourceLocation*) /home/xxx/data/git/llvm-project/clang/lib/Parse/ParseDecl.cpp:1700:10
#&#8203;38 0x000000000c873179 clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::Parser::ParsedAttributesWithRange&, clang::SourceLocation*) /home/xxx/data/git/llvm-project/clang/lib/Parse/ParseDecl.cpp:0:12
#&#8203;39 0x000000000ca08d41 clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::Parser::ParsedAttributesWithRange&) /home/xxx/data/git/llvm-project/clang/lib/Parse/ParseStmt.cpp:0:13
#&#8203;40 0x000000000ca081a6 clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*) /home/xxx/data/git/llvm-project/clang/lib/Parse/ParseStmt.cpp:106:20
#&#8203;41 0x000000000ca1c77e clang::Parser::ParseCompoundStatementBody(bool) /home/xxx/data/git/llvm-project/clang/lib/Parse/ParseStmt.cpp:1089:11
#&#8203;42 0x000000000ca1f748 clang::ActionResult<clang::Stmt*, true>::isInvalid() const /home/xxx/data/git/llvm-project/clang/include/clang/Sema/Ownership.h:0:0
#&#8203;43 0x000000000ca1f748 clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) /home/xxx/data/git/llvm-project/clang/lib/Parse/ParseStmt.cpp:2240:0
#&#8203;44 0x000000000c833117 clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) /home/xxx/data/git/llvm-project/clang/lib/Parse/Parser.cpp:1339:10
#&#8203;45 0x000000000c88224e clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::SourceLocation*, clang::Parser::ForRangeInit*) /home/xxx/data/git/llvm-project/clang/lib/Parse/ParseDecl.cpp:1926:18
#&#8203;46 0x000000000c83020d clang::Parser::ParseDeclOrFunctionDefInternal(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec&, clang::AccessSpecifier) /home/xxx/data/git/llvm-project/clang/lib/Parse/Parser.cpp:0:10
#&#8203;47 0x000000000c82e939 clang::Parser::ObjCDeclContextSwitch::~ObjCDeclContextSwitch() /home/xxx/data/git/llvm-project/clang/include/clang/Parse/Parser.h:0:0
#&#8203;48 0x000000000c82e939 clang::Parser::ParseDeclarationOrFunctionDefinition(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec*, clang::AccessSpecifier) /home/xxx/data/git/llvm-project/clang/lib/Parse/Parser.cpp:1116:0
#&#8203;49 0x000000000c82c6a1 clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec*) /home/xxx/data/git/llvm-project/clang/lib/Parse/Parser.cpp:935:12
#&#8203;50 0x000000000c827ecc clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, bool) /home/xxx/data/git/llvm-project/clang/lib/Parse/Parser.cpp:683:10
#&#8203;51 0x000000000c826ccc clang::Parser::ParseFirstTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&) /home/xxx/data/git/llvm-project/clang/lib/Parse/Parser.cpp:555:26
#&#8203;52 0x000000000c81cf4a clang::ParseAST(clang::Sema&, bool, bool) /home/xxx/data/git/llvm-project/clang/lib/Parse/ParseAST.cpp:157:15
#&#8203;53 0x000000000861c2a2 clang::ASTFrontendAction::ExecuteAction() /home/xxx/data/git/llvm-project/clang/lib/Frontend/FrontendAction.cpp:1059:1
#&#8203;54 0x00000000099decd8 clang::CodeGenAction::ExecuteAction() /home/xxx/data/git/llvm-project/clang/lib/CodeGen/CodeGenAction.cpp:1184:28
#&#8203;55 0x000000000861a51a clang::FrontendAction::Execute() /home/xxx/data/git/llvm-project/clang/lib/Frontend/FrontendAction.cpp:954:10
#&#8203;56 0x000000000854eaa7 llvm::Error::operator bool() /home/xxx/data/git/llvm-project/llvm/include/llvm/Support/Error.h:0:0
#&#8203;57 0x000000000854eaa7 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) /home/xxx/data/git/llvm-project/clang/lib/Frontend/CompilerInstance.cpp:984:0
#&#8203;58 0x00000000088f183f clang::CompilerInstance::getFrontendOpts() /home/xxx/data/git/llvm-project/clang/include/clang/Frontend/CompilerInstance.h:0:0
#&#8203;59 0x00000000088f183f clang::ExecuteCompilerInvocation(clang::CompilerInstance*) /home/xxx/data/git/llvm-project/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:279:0
#&#8203;60 0x0000000000b094cc llvm::TimeTraceScope::~TimeTraceScope() /home/xxx/data/git/llvm-project/llvm/include/llvm/Support/TimeProfiler.h:0:0
#&#8203;61 0x0000000000b094cc cc1_main(llvm::ArrayRef<char const*>, char const*, void*) /home/xxx/data/git/llvm-project/clang/tools/driver/cc1_main.cpp:241:0
#&#8203;62 0x0000000000afaf3b ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&) /home/xxx/data/git/llvm-project/clang/tools/driver/driver.cpp:330:12
#&#8203;63 0x0000000000af6966 main /home/xxx/data/git/llvm-project/clang/tools/driver/driver.cpp:407:12
#&#8203;64 0x00007f0e741d0b97 __libc_start_main /build/glibc-2ORdQG/glibc-2.27/csu/../csu/libc-start.c:344:0
#&#8203;65 0x0000000000af38ea _start (/data/xxx/git/llvm-project/build/bin/clang-11+0xaf38ea)
clang-11: error: unable to execute command: Segmentation fault (core dumped)
clang-11: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 11.1.0 (https://github.com/llvm/llvm-project.git 1fdec59bffc11ae37eb51a1b9869f0696bfd5312)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /data/xxx/git/llvm-project/build/bin
clang-11: note: diagnostic msg:
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang-11: note: diagnostic msg: /tmp/test-398094.cpp
clang-11: note: diagnostic msg: /tmp/test-398094.sh
clang-11: note: diagnostic msg:

********************
@fhahn
Copy link
Contributor

fhahn commented Feb 15, 2021

Also crashes on trunk https://godbolt.org/z/v17hqr

0.	Program arguments: /opt/compiler-explorer/clang-trunk/bin/clang++ -g -o ./output.s -mllvm --x86-asm-syntax=intel -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics <source>
1.	<source>:3:13: current parser token ';'
2.	<source>:1:12: parsing function body 'main'
3.	<source>:1:12: in compound statement ('{}')
4.	<source>:2:14: lambda expression parsing
5.	<source>:2:40: in compound statement ('{}')
 #&#8203;0 0x000055d1894d7bec llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x303ebec)
 #&#8203;1 0x000055d1894d5994 llvm::sys::RunSignalHandlers() (/opt/compiler-explorer/clang-trunk/bin/clang+++0x303c994)
 #&#8203;2 0x000055d1894d5c15 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x303cc15)
 #&#8203;3 0x000055d18943c5b8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #&#8203;4 0x00007fe9f6b523c0 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x153c0)
 #&#8203;5 0x000055d18b776c17 clang::Sema::ActOnCapScopeReturnStmt(clang::SourceLocation, clang::Expr*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x52ddc17)
 #&#8203;6 0x000055d18b77763f clang::Sema::BuildReturnStmt(clang::SourceLocation, clang::Expr*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x52de63f)
 #&#8203;7 0x000055d18b7785a2 clang::Sema::ActOnReturnStmt(clang::SourceLocation, clang::Expr*, clang::Scope*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x52df5a2)
 #&#8203;8 0x000055d18b1bf775 clang::Parser::ParseReturnStatement() (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4d26775)
 #&#8203;9 0x000055d18b1c270f clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::Parser::ParsedAttributesWithRange&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4d2970f)
#&#8203;10 0x000055d18b1c2dcd clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4d29dcd)
#&#8203;11 0x000055d18b1c38e1 clang::Parser::ParseCompoundStatementBody(bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4d2a8e1)
#&#8203;12 0x000055d18b1c40be clang::Parser::ParseCompoundStatement(bool, unsigned int) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4d2b0be)
#&#8203;13 0x000055d18b1700ee clang::Parser::ParseParenExpression(clang::Parser::ParenParseOption&, bool, bool, clang::OpaquePtr<clang::QualType>&, clang::SourceLocation&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4cd70ee)
#&#8203;14 0x000055d18b167cce clang::Parser::ParseCastExpression(clang::Parser::CastParseKind, bool, bool&, clang::Parser::TypeCastState, bool, bool*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4ccecce)
#&#8203;15 0x000055d18b169fb6 clang::Parser::ParseCastExpression(clang::Parser::CastParseKind, bool, clang::Parser::TypeCastState, bool, bool*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4cd0fb6)
#&#8203;16 0x000055d18b16b174 clang::Parser::ParseAssignmentExpression(clang::Parser::TypeCastState) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4cd2174)
#&#8203;17 0x000055d18b13b1c6 clang::Parser::ParseAttributeArgsCommon(clang::IdentifierInfo*, clang::SourceLocation, clang::ParsedAttributes&, clang::SourceLocation*, clang::IdentifierInfo*, clang::SourceLocation, clang::AttributeCommonInfo::Syntax) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4ca21c6)
#&#8203;18 0x000055d18b13d74c clang::Parser::ParseGNUAttributeArgs(clang::IdentifierInfo*, clang::SourceLocation, clang::ParsedAttributes&, clang::SourceLocation*, clang::IdentifierInfo*, clang::SourceLocation, clang::AttributeCommonInfo::Syntax, clang::Declarator*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4ca474c)
#&#8203;19 0x000055d18b13dcc6 clang::Parser::ParseGNUAttributes(clang::ParsedAttributes&, clang::SourceLocation*, clang::Parser::LateParsedAttrList*, clang::Declarator*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4ca4cc6)
#&#8203;20 0x000055d18b13edee clang::Parser::ParseAttributes(unsigned int, clang::Parser::ParsedAttributesWithRange&, clang::SourceLocation*, clang::Parser::LateParsedAttrList*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4ca5dee)
#&#8203;21 0x000055d18b17fe06 clang::Parser::ParseLambdaExpressionAfterIntroducer(clang::LambdaIntroducer&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4ce6e06)
#&#8203;22 0x000055d18b180523 clang::Parser::ParseLambdaExpression() (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4ce7523)
#&#8203;23 0x000055d18b168b83 clang::Parser::ParseCastExpression(clang::Parser::CastParseKind, bool, bool&, clang::Parser::TypeCastState, bool, bool*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4ccfb83)
#&#8203;24 0x000055d18b169fb6 clang::Parser::ParseCastExpression(clang::Parser::CastParseKind, bool, clang::Parser::TypeCastState, bool, bool*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4cd0fb6)
#&#8203;25 0x000055d18b16b174 clang::Parser::ParseAssignmentExpression(clang::Parser::TypeCastState) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4cd2174)
#&#8203;26 0x000055d18b136de7 clang::Parser::ParseDeclarationAfterDeclaratorAndAttributes(clang::Declarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4c9dde7)
#&#8203;27 0x000055d18b147975 clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4cae975)
#&#8203;28 0x000055d18b14855d clang::Parser::ParseSimpleDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::Parser::ParsedAttributesWithRange&, bool, clang::Parser::ForRangeInit*, clang::SourceLocation*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4caf55d)
#&#8203;29 0x000055d18b148882 clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::Parser::ParsedAttributesWithRange&, clang::SourceLocation*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4caf882)
#&#8203;30 0x000055d18b1c2b59 clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::Parser::ParsedAttributesWithRange&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4d29b59)
#&#8203;31 0x000055d18b1c2dcd clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4d29dcd)
#&#8203;32 0x000055d18b1c38e1 clang::Parser::ParseCompoundStatementBody(bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4d2a8e1)
#&#8203;33 0x000055d18b1c7103 clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4d2e103)
#&#8203;34 0x000055d18b11f267 clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4c86267)
#&#8203;35 0x000055d18b147885 clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4cae885)
#&#8203;36 0x000055d18b11a9c1 clang::Parser::ParseDeclOrFunctionDefInternal(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4c819c1)
#&#8203;37 0x000055d18b11b0f1 clang::Parser::ParseDeclarationOrFunctionDefinition(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (.part.241) Parser.cpp:0:0
#&#8203;38 0x000055d18b121079 clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4c88079)
#&#8203;39 0x000055d18b1225f9 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4c895f9)
#&#8203;40 0x000055d18b122be5 clang::Parser::ParseFirstTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4c89be5)
#&#8203;41 0x000055d18b115823 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4c7c823)
#&#8203;42 0x000055d18a34d932 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3eb4932)
#&#8203;43 0x000055d189d4c9b1 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-trunk/bin/clang+++0x38b39b1)
#&#8203;44 0x000055d189ce35f3 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x384a5f3)
#&#8203;45 0x000055d189e13a13 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x397aa13)
#&#8203;46 0x000055d18747f91c cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0xfe691c)
#&#8203;47 0x000055d18747ba3d ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&) driver.cpp:0:0
#&#8203;48 0x000055d189b9a0f5 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optional<llvm::StringRef> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#&#8203;49 0x000055d18943c693 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x2fa3693)
#&#8203;50 0x000055d189b9aa28 clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optional<llvm::StringRef> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*, bool*) const (.part.165) Job.cpp:0:0
#&#8203;51 0x000055d189b73b29 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&) const (/opt/compiler-explorer/clang-trunk/bin/clang+++0x36dab29)
#&#8203;52 0x000055d189b74d4f clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*> >&) const (/opt/compiler-explorer/clang-trunk/bin/clang+++0x36dbd4f)
#&#8203;53 0x000055d189b84a95 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*> >&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x36eba95)
#&#8203;54 0x000055d187399dd4 main (/opt/compiler-explorer/clang-trunk/bin/clang+++0xf00dd4)
#&#8203;55 0x00007fe9f66030b3 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b3)
#&#8203;56 0x000055d18747b5ba _start (/opt/compiler-explorer/clang-trunk/bin/clang+++0xfe25ba)
clang-13: error: clang frontend command failed with exit code 139 (use -v to see invocation)
Compiler returned: 139

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 11, 2021
@Endilll
Copy link
Contributor

Endilll commented Sep 10, 2023

Still crashing as of post-17 trunk: https://godbolt.org/z/54YrjjK6W

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++ -gdwarf-4 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics <source>
1.	<source>:3:13: current parser token ';'
2.	<source>:1:12: parsing function body 'main'
3.	<source>:1:12: in compound statement ('{}')
4.	<source>:2:14: lambda expression parsing
5.	<source>:2:40: in compound statement ('{}')
 #0 0x00000000036afc28 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x36afc28)
 #1 0x00000000036ad8ec llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x36ad8ec)
 #2 0x00000000035f6d08 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007f3eceae2420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #4 0x00000000067534bc clang::Sema::ActOnCapScopeReturnStmt(clang::SourceLocation, clang::Expr*, clang::Sema::NamedReturnInfo&, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x67534bc)
 #5 0x0000000006753fa1 clang::Sema::BuildReturnStmt(clang::SourceLocation, clang::Expr*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6753fa1)
 #6 0x00000000067565df clang::Sema::ActOnReturnStmt(clang::SourceLocation, clang::Expr*, clang::Scope*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x67565df)
 #7 0x0000000005ee0847 clang::Parser::ParseReturnStatement() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5ee0847)
 #8 0x0000000005ee3b2b clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::ParsedAttributes&, clang::ParsedAttributes&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5ee3b2b)
 #9 0x0000000005ee5128 clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5ee5128)
#10 0x0000000005ee6069 clang::Parser::ParseCompoundStatementBody(bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5ee6069)
#11 0x0000000005ee7a9a clang::Parser::ParseCompoundStatement(bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5ee7a9a)
#12 0x0000000005e77152 clang::Parser::ParseParenExpression(clang::Parser::ParenParseOption&, bool, bool, clang::OpaquePtr<clang::QualType>&, clang::SourceLocation&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5e77152)
#13 0x0000000005e6bc25 clang::Parser::ParseCastExpression(clang::Parser::CastParseKind, bool, bool&, clang::Parser::TypeCastState, bool, bool*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5e6bc25)
#14 0x0000000005e6dc9a clang::Parser::ParseCastExpression(clang::Parser::CastParseKind, bool, clang::Parser::TypeCastState, bool, bool*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5e6dc9a)
#15 0x0000000005e6de39 clang::Parser::ParseAssignmentExpression(clang::Parser::TypeCastState) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5e6de39)
#16 0x0000000005e2bed2 clang::Parser::ParseAttributeArgumentList(clang::IdentifierInfo const&, llvm::SmallVectorImpl<clang::Expr*>&, clang::ParsedAttributeArgumentsProperties) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5e2bed2)
#17 0x0000000005e32b1c clang::Parser::ParseAttributeArgsCommon(clang::IdentifierInfo*, clang::SourceLocation, clang::ParsedAttributes&, clang::SourceLocation*, clang::IdentifierInfo*, clang::SourceLocation, clang::AttributeCommonInfo::Form) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5e32b1c)
#18 0x0000000005e36a13 clang::Parser::ParseGNUAttributeArgs(clang::IdentifierInfo*, clang::SourceLocation, clang::ParsedAttributes&, clang::SourceLocation*, clang::IdentifierInfo*, clang::SourceLocation, clang::AttributeCommonInfo::Form, clang::Declarator*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5e36a13)
#19 0x0000000005e374e8 clang::Parser::ParseGNUAttributes(clang::ParsedAttributes&, clang::Parser::LateParsedAttrList*, clang::Declarator*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5e374e8)
#20 0x0000000005e3a488 clang::Parser::ParseAttributes(unsigned int, clang::ParsedAttributes&, clang::Parser::LateParsedAttrList*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5e3a488)
#21 0x0000000005e81e09 clang::Parser::ParseLambdaExpressionAfterIntroducer(clang::LambdaIntroducer&)::'lambda0'()::operator()() const ParseExprCXX.cpp:0:0
#22 0x0000000005e8d44d clang::Parser::ParseLambdaExpressionAfterIntroducer(clang::LambdaIntroducer&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5e8d44d)
#23 0x0000000005e8df5b clang::Parser::ParseLambdaExpression() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5e8df5b)
#24 0x0000000005e6c305 clang::Parser::ParseCastExpression(clang::Parser::CastParseKind, bool, bool&, clang::Parser::TypeCastState, bool, bool*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5e6c305)
#25 0x0000000005e6dc9a clang::Parser::ParseCastExpression(clang::Parser::CastParseKind, bool, clang::Parser::TypeCastState, bool, bool*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5e6dc9a)
#26 0x0000000005e6de39 clang::Parser::ParseAssignmentExpression(clang::Parser::TypeCastState) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5e6de39)
#27 0x0000000005e2e5bd clang::Parser::ParseDeclarationAfterDeclaratorAndAttributes(clang::Declarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5e2e5bd)
#28 0x0000000005e3c040 clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5e3c040)
#29 0x0000000005e44395 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+++0x5e44395)
#30 0x0000000005e44837 clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::ParsedAttributes&, clang::SourceLocation*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5e44837)
#31 0x0000000005ee4420 clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::ParsedAttributes&, clang::ParsedAttributes&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5ee4420)
#32 0x0000000005ee5128 clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5ee5128)
#33 0x0000000005ee6069 clang::Parser::ParseCompoundStatementBody(bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5ee6069)
#34 0x0000000005ee798a clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5ee798a)
#35 0x0000000005e15151 clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5e15151)
#36 0x0000000005e3c748 clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5e3c748)
#37 0x0000000005e0906b clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5e0906b)
#38 0x0000000005e0979f clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (.part.0) Parser.cpp:0:0
#39 0x0000000005e0feb4 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5e0feb4)
#40 0x0000000005e106bd clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5e106bd)
#41 0x0000000005e10af0 clang::Parser::ParseFirstTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5e10af0)
#42 0x0000000005e049e2 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5e049e2)
#43 0x000000000490f578 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x490f578)
#44 0x0000000004177f89 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4177f89)
#45 0x00000000040f818e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x40f818e)
#46 0x00000000042561fe clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x42561fe)
#47 0x0000000000bd6ea0 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xbd6ea0)
#48 0x0000000000bcf0ca ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#49 0x0000000003f59309 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
#50 0x00000000035f71b4 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x35f71b4)
#51 0x0000000003f598ff 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
#52 0x0000000003f21c85 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3f21c85)
#53 0x0000000003f226ed 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+++0x3f226ed)
#54 0x0000000003f2a615 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3f2a615)
#55 0x0000000000bd4cac clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xbd4cac)
#56 0x0000000000ad14a1 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xad14a1)
#57 0x00007f3ece586083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#58 0x0000000000bcebae _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xbcebae)
clang++: error: clang frontend command failed with exit code 139 (use -v to see invocation)

@Endilll Endilll added clang:frontend Language frontend issues, e.g. anything involving "Sema" confirmed Verified by a second party crash Prefer [crash-on-valid] or [crash-on-invalid] labels Sep 10, 2023
@llvmbot
Copy link
Member Author

llvmbot commented Sep 10, 2023

@llvm/issue-subscribers-clang-frontend

@shafik
Copy link
Collaborator

shafik commented Sep 10, 2023

This looks tough, so we are parsing the lambda and get to Parser::ParseAttributeArgumentList(...) here:

Expr = ParseAssignmentExpression();

I think b/c it just has to be a balance token sequence. We eventually get here:

if (isa<CapturingScopeInfo>(getCurFunction()))
return ActOnCapScopeReturnStmt(ReturnLoc, RetValExp, NRInfo,
SupressSimplerImplicitMoves);

so we know we are parsing a lambda IIUC but we don't realize that being here does not make sense when parsing attribute argument list and therefore can't error out.

CC @zygoloid @cor3ntin for possible advice on tackling this one

@cor3ntin
Copy link
Contributor

cor3ntin commented Sep 11, 2023

Lambdas do not have types until after the declarator is parsed.
BuildReturnStmt do seem to be fairly protected against null types.

However, ActOnCapScopeReturnStmt calls

static bool hasDeducedReturnType(FunctionDecl *FD) {
  const FunctionProtoType *FPT =
      FD->getTypeSourceInfo()->getType()->castAs<FunctionProtoType>();
  return FPT->getReturnType()->isUndeducedType();
}

Adding

 if(CurLambda && CurLambda->CallOperator->getType().isNull()) {
    return StmtError();
 }

at the very top of ActOnCapScopeReturnStmt does fix the crash and produces an error similar to what we get for functions
ie,

void test () {
  struct S {
    int f() __attribute__((b(({
        return 0;
    }
};
}

@cor3ntin
Copy link
Contributor

I don't have the bandwidth to make a pr, but with the above guidance, it should be straightforward

@cor3ntin cor3ntin added the good first issue https://github.com/llvm/llvm-project/contribute label Sep 11, 2023
@llvmbot
Copy link
Member Author

llvmbot commented Sep 11, 2023

Hi!

This issue may be a good introductory issue for people new to working on LLVM. If you would like to work on this issue, your first steps are:

  1. Assign the issue to you.
  2. Fix the issue locally.
  3. Run the test suite locally.
    3.1) Remember that the subdirectories under test/ create fine-grained testing targets, so you can
    e.g. use make check-clang-ast to only run Clang's AST tests.
  4. Create a git commit
  5. Run git clang-format HEAD~1 to format your changes.
  6. Submit the patch to Phabricator.
    6.1) Detailed instructions can be found here

For more instructions on how to submit a patch to LLVM, see our documentation.

If you have any further questions about this issue, don't hesitate to ask via a comment on this Github issue.

@llvm/issue-subscribers-good-first-issue

@pfusik pfusik self-assigned this Sep 15, 2023
@pfusik
Copy link
Contributor

pfusik commented Sep 18, 2023

[](void)__attribute__((b(({

is a lambda with no parameters and a GCC-style attribute b. There is one argument for the b attribute, which is a GCC extension statement expression ({ return 0; }).

Note that statement expressions have the value of their last statement.

The following is accepted by both GCC and Clang:

char *__attribute__((aligned(({ 8; })))) *f;

It is unclear to me how to treat non-local control flow (return, break etc) in statement expressions in attributes. It probably should be a compile-time error, however GCC accepts:

[]()__attribute__((b(({ return 0; })))){};

For now, I created https://reviews.llvm.org/D159528 as per the above instructions. Should I file a GH PR instead?

@pfusik
Copy link
Contributor

pfusik commented Sep 18, 2023

The issue is not specific to GCC-style attributes and is also reproducible with C++11 attributes.

@cor3ntin
Copy link
Contributor

For now, I created https://reviews.llvm.org/D159528 as per the above instructions. Should I file a GH PR instead?

Yes !

pfusik added a commit to pfusik/llvm-project that referenced this issue Sep 19, 2023
…expr

clang was crashing on a lambda attribute with a statement expression
that contained a `return`.
It attempted to access the lambda type which was unknown at that point.

Fixes llvm#48527
pfusik added a commit that referenced this issue Sep 19, 2023
…expr (#66643)

clang was crashing on a lambda attribute with a statement expression
that contained a `return`.
It attempted to access the lambda type which was unknown at that point.

Fixes #48527
ZijunZhaoCCK pushed a commit to ZijunZhaoCCK/llvm-project that referenced this issue Sep 19, 2023
…expr (llvm#66643)

clang was crashing on a lambda attribute with a statement expression
that contained a `return`.
It attempted to access the lambda type which was unknown at that point.

Fixes llvm#48527
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla c++ clang:frontend Language frontend issues, e.g. anything involving "Sema" confirmed Verified by a second party crash Prefer [crash-on-valid] or [crash-on-invalid] good first issue https://github.com/llvm/llvm-project/contribute
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants