Issue 242318
Summary [clang] decltype of lambda returning double auto reference crash
Labels clang
Assignees
Reporter Pedda1712
    The following:
```c++
void foo() {
  []() -> decltype([](auto) -> auto&& {
 return 1;
  }(1)) {};
}
```
results in a crash on trunk (https://godbolt.org/z/vhqb14fx4). Goes back to clang-17.

This test case was generated by a fuzzer.

```
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 <source>
1.	<source>:4:6: current parser token ')'
2.	<source>:1:12: parsing function body 'foo'
3.	<source>:1:12: in compound statement ('{}')
4.	<source>:2:3: lambda _expression_ parsing
5.	<source>:2:20: instantiating function definition 'foo()::(lambda)::clang++: /root/llvm-project/llvm/tools/clang/include/clang/AST/TypeBase.h:954: const clang::ExtQualsTypeCommonBase* clang::QualType::getCommonPtr() const: Assertion `!isNull() && "Cannot retrieve a NULL type pointer"' failed.
 #0 0x0000000004f4f778 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4f4f778)
  #1 0x0000000004f4c9d4 llvm::sys::RunSignalHandlers() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4f4c9d4)
  #2 0x0000000004f4cb4e SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
 #3 0x0000000004f4cbf8 SignalHandlerTerminate(int, siginfo_t*, void*) Signals.cpp:0:0
  #4 0x00007f196d445330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
  #5 0x00007f196d49ec0c pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x9ec0c)
  #6 0x00007f196d44527e raise (/lib/x86_64-linux-gnu/libc.so.6+0x4527e)
  #7 0x00007f196d4288ff abort (/lib/x86_64-linux-gnu/libc.so.6+0x288ff)
  #8 0x00007f196d42881b (/lib/x86_64-linux-gnu/libc.so.6+0x2881b)
  #9 0x00007f196d43b517 (/lib/x86_64-linux-gnu/libc.so.6+0x3b517)
 #10 0x000000000533ce54 (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x533ce54)
 #11 0x000000000a28d097 clang::NamedDecl::printNestedNameSpecifier(llvm::raw_ostream&, clang::PrintingPolicy const&) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xa28d097)
 #12 0x000000000a28d33f clang::NamedDecl::printQualifiedName(llvm::raw_ostream&, clang::PrintingPolicy const&) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xa28d33f)
 #13 0x000000000a28e4dd clang::FunctionDecl::getNameForDiagnostic(llvm::raw_ostream&, clang::PrintingPolicy const&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xa28e4dd)
 #14 0x000000000a27a5b3 clang::PrettyDeclStackTraceEntry::print(llvm::raw_ostream&) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xa27a5b3)
 #15 0x0000000004ec6b87 PrintCurStackTrace(llvm::raw_ostream&) PrettyStackTrace.cpp:0:0
 #16 0x0000000004f4c9d4 llvm::sys::RunSignalHandlers() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4f4c9d4)
 #17 0x0000000004f4d00c llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4f4d00c)
 #18 0x0000000004e86d28 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #19 0x00007f196d445330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
 #20 0x00007f196d49ec0c pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x9ec0c)
 #21 0x00007f196d44527e raise (/lib/x86_64-linux-gnu/libc.so.6+0x4527e)
 #22 0x00007f196d4288ff abort (/lib/x86_64-linux-gnu/libc.so.6+0x288ff)
 #23 0x00007f196d42881b (/lib/x86_64-linux-gnu/libc.so.6+0x2881b)
 #24 0x00007f196d43b517 (/lib/x86_64-linux-gnu/libc.so.6+0x3b517)
 #25 0x000000000533ce54 (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x533ce54)
 #26 0x000000000a28d097 clang::NamedDecl::printNestedNameSpecifier(llvm::raw_ostream&, clang::PrintingPolicy const&) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xa28d097)
 #27 0x000000000a28d33f clang::NamedDecl::printQualifiedName(llvm::raw_ostream&, clang::PrintingPolicy const&) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xa28d33f)
 #28 0x000000000a28e4dd clang::FunctionDecl::getNameForDiagnostic(llvm::raw_ostream&, clang::PrintingPolicy const&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xa28e4dd)
 #29 0x000000000a0a9235 clang::FormatASTNodeDiagnosticArgument(clang::DiagnosticsEngine::ArgumentKind, long, llvm::StringRef, llvm::StringRef, llvm::ArrayRef<std::pair<clang::DiagnosticsEngine::ArgumentKind, long>>, llvm::SmallVectorImpl<char>&, void*, llvm::ArrayRef<long>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xa0a9235)
 #30 0x0000000005304b6c clang::Diagnostic::FormatDiagnostic(char const*, char const*, llvm::SmallVectorImpl<char>&) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5304b6c)
 #31 0x0000000005de0936 clang::TextDiagnosticPrinter::HandleDiagnostic(clang::DiagnosticsEngine::Level, clang::Diagnostic const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5de0936)
 #32 0x00000000053027c0 clang::DiagnosticsEngine::Report(clang::DiagnosticsEngine::Level, clang::Diagnostic const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x53027c0)
 #33 0x0000000005302ed5 clang::DiagnosticsEngine::ProcessDiag(clang::DiagnosticBuilder const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5302ed5)
 #34 0x0000000005302fb5 clang::DiagnosticsEngine::EmitDiagnostic(clang::DiagnosticBuilder const&, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5302fb5)
 #35 0x00000000091baf8f void llvm::function_ref<void (clang::SourceLocation, clang::PartialDiagnostic)>::callback_fn<clang::Sema::getDefaultDiagFunc()::'lambda'(clang::SourceLocation, clang::PartialDiagnostic)>(long, clang::SourceLocation, clang::PartialDiagnostic) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x91baf8f)
 #36 0x0000000009bc95ec llvm::function_ref<void (clang::SourceLocation, clang::PartialDiagnostic)>::operator()(clang::SourceLocation, clang::PartialDiagnostic) const (.isra.0) SemaTemplateInstantiate.cpp:0:0
 #37 0x0000000009bcff4c clang::Sema::PrintInstantiationStack(llvm::function_ref<void (clang::SourceLocation, clang::PartialDiagnostic)>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x9bcff4c)
 #38 0x00000000091cf365 clang::Sema::EmitDiagnostic(unsigned int, clang::DiagnosticBuilder const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x91cf365)
 #39 0x0000000009256852 clang::SemaBase::ImmediateDiagBuilder::~ImmediateDiagBuilder() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x9256852)
 #40 0x00000000091b1188 clang::SemaBase::SemaDiagnosticBuilder::~SemaDiagnosticBuilder() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x91b1188)
 #41 0x0000000009d6fa68 clang::sema::checkExprLifetimeImpl(clang::Sema&, clang::InitializedEntity const*, clang::InitializedEntity const*, clang::sema::(anonymous namespace)::LifetimeKind, clang::sema::AssignedEntity const*, clang::sema::CapturingEntity const*, clang::Expr*)::'lambda'(llvm::SmallVectorImpl<clang::sema::(anonymous namespace)::IndirectLocalPathEntry> const&, clang::Expr*, clang::sema::(anonymous namespace)::ReferenceKind)::operator()(llvm::SmallVectorImpl<clang::sema::(anonymous namespace)::IndirectLocalPathEntry> const&, clang::Expr*, clang::sema::(anonymous namespace)::ReferenceKind) const CheckExprLifetime.cpp:0:0
 #42 0x0000000009d6d9c4 clang::sema::visitLocalsRetainedByReferenceBinding(llvm::SmallVectorImpl<clang::sema::(anonymous namespace)::IndirectLocalPathEntry>&, clang::Expr*, clang::sema::(anonymous namespace)::ReferenceKind, llvm::function_ref<bool (llvm::SmallVectorImpl<clang::sema::(anonymous namespace)::IndirectLocalPathEntry>&, clang::Expr*, clang::sema::(anonymous namespace)::ReferenceKind)>) CheckExprLifetime.cpp:0:0
 #43 0x0000000009d6e5a0 clang::sema::checkExprLifetimeImpl(clang::Sema&, clang::InitializedEntity const*, clang::InitializedEntity const*, clang::sema::(anonymous namespace)::LifetimeKind, clang::sema::AssignedEntity const*, clang::sema::CapturingEntity const*, clang::Expr*) CheckExprLifetime.cpp:0:0
 #44 0x0000000009d6e98a clang::sema::checkInitLifetime(clang::Sema&, clang::InitializedEntity const&, clang::Expr*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x9d6e98a)
 #45 0x000000000974e2a3 clang::InitializationSequence::Perform(clang::Sema&, clang::InitializedEntity const&, clang::InitializationKind const&, llvm::MutableArrayRef<clang::Expr*>, clang::QualType*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x974e2a3)
 #46 0x0000000009750e39 clang::Sema::PerformCopyInitialization(clang::InitializedEntity const&, clang::SourceLocation, clang::ActionResult<clang::Expr*, true>, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x9750e39)
 #47 0x00000000099e1c64 clang::Sema::PerformMoveOrCopyInitialization(clang::InitializedEntity const&, clang::Sema::NamedReturnInfo const&, clang::Expr*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x99e1c64)
 #48 0x00000000099f98ed clang::Sema::ActOnCapScopeReturnStmt(clang::SourceLocation, clang::Expr*, clang::Sema::NamedReturnInfo&, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x99f98ed)
 #49 0x00000000099f9dba clang::Sema::BuildReturnStmt(clang::SourceLocation, clang::Expr*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x99f9dba)
 #50 0x0000000009bdd4b5 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformCompoundStmt(clang::CompoundStmt*, bool) SemaTemplateInstantiate.cpp:0:0
 #51 0x0000000009c29742 clang::Sema::SubstStmt(clang::Stmt*, clang::MultiLevelTemplateArgumentList const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x9c29742)
 #52 0x0000000009ccb827 clang::Sema::InstantiateFunctionDefinition(clang::SourceLocation, clang::FunctionDecl*, bool, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x9ccb827)
 #53 0x000000000ab955b1 clang::StackExhaustionHandler::runWithSufficientStackSpace(clang::SourceLocation, llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xab955b1)
 #54 0x0000000009b12f06 clang::Sema::DeduceReturnType(clang::FunctionDecl*, clang::SourceLocation, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x9b12f06)
 #55 0x00000000095a5ebb clang::Sema::DiagnoseUseOfDecl(clang::NamedDecl*, llvm::ArrayRef<clang::SourceLocation>, clang::ObjCInterfaceDecl const*, bool, bool, clang::ObjCInterfaceDecl*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x95a5ebb)
 #56 0x000000000996b8da CreateFunctionRefExpr(clang::Sema&, clang::NestedNameSpecifierLoc, clang::SourceLocation, clang::FunctionDecl*, clang::NamedDecl*, clang::Expr const*, bool, clang::DeclarationNameInfo const&, clang::TemplateArgumentListInfo const*) SemaOverload.cpp:0:0
 #57 0x00000000099be592 clang::Sema::BuildCallToObjectOfClassType(clang::Scope*, clang::Expr*, clang::SourceLocation, llvm::MutableArrayRef<clang::Expr*>, clang::SourceLocation) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x99be592)
 #58 0x00000000095f1eeb clang::Sema::BuildCallExpr(clang::Scope*, clang::Expr*, clang::SourceLocation, llvm::MutableArrayRef<clang::Expr*>, clang::SourceLocation, clang::Expr*, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x95f1eeb)
 #59 0x00000000095f726f clang::Sema::ActOnCallExpr(clang::Scope*, clang::Expr*, clang::SourceLocation, llvm::MutableArrayRef<clang::Expr*>, clang::SourceLocation, clang::Expr*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x95f726f)
 #60 0x00000000090a38e3 clang::Parser::ParsePostfixExpressionSuffix(clang::ActionResult<clang::Expr*, true>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x90a38e3)
 #61 0x000000000909c45a clang::Parser::ParseCastExpression(clang::CastParseKind, bool, bool&, clang::TypoCorrectionTypeBehavior, bool, bool*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x909c45a)
 #62 0x000000000909e707 clang::Parser::ParseCastExpression(clang::CastParseKind, bool, clang::TypoCorrectionTypeBehavior, bool, bool*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x909e707)
 #63 0x000000000909e799 clang::Parser::ParseAssignmentExpression(clang::TypoCorrectionTypeBehavior) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x909e799)
 #64 0x00000000090a2ee9 clang::Parser::ParseExpression(clang::TypoCorrectionTypeBehavior) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x90a2ee9)
 #65 0x000000000907e105 clang::Parser::ParseDecltypeSpecifier(clang::DeclSpec&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x907e105)
 #66 0x00000000090bc161 clang::Parser::ParseOptionalCXXScopeSpecifier(clang::CXXScopeSpec&, clang::OpaquePtr<clang::QualType>, bool, bool, bool*, bool, clang::IdentifierInfo const**, bool, bool, bool, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x90bc161)
 #67 0x0000000009020ef0 clang::Parser::TryAnnotateCXXScopeToken(bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x9020ef0)
 #68 0x0000000009065c40 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+++0x9065c40)
 #69 0x0000000009067322 clang::Parser::ParseSpecifierQualifierList(clang::DeclSpec&, clang::ImplicitTypenameContext, clang::AccessSpecifier, clang::Parser::DeclSpecContext, clang::LateParsedAttrList*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x9067322)
 #70 0x0000000009067883 clang::Parser::ParseTypeName(clang::SourceRange*, clang::DeclaratorContext, clang::AccessSpecifier, clang::Decl**, clang::ParsedAttributes*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x9067883)
 #71 0x00000000090b8d30 clang::Parser::ParseLambdaExpressionAfterIntroducer(clang::LambdaIntroducer&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x90b8d30)
 #72 0x00000000090b922b clang::Parser::ParseLambdaExpression() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x90b922b)
 #73 0x000000000909de05 clang::Parser::ParseCastExpression(clang::CastParseKind, bool, bool&, clang::TypoCorrectionTypeBehavior, bool, bool*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x909de05)
 #74 0x000000000909e707 clang::Parser::ParseCastExpression(clang::CastParseKind, bool, clang::TypoCorrectionTypeBehavior, bool, bool*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x909e707)
 #75 0x000000000909e799 clang::Parser::ParseAssignmentExpression(clang::TypoCorrectionTypeBehavior) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x909e799)
 #76 0x00000000090a2ee9 clang::Parser::ParseExpression(clang::TypoCorrectionTypeBehavior) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x90a2ee9)
 #77 0x0000000009133af8 clang::Parser::ParseExprStatem<truncated>Please see the issue for the entire body.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to