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

Regression: Clang crash exit code 139 OR rejects-valid when decltype-ing the result of a templated lambda. #89853

Closed
13steinj opened this issue Apr 24, 2024 · 3 comments · Fixed by #89934
Assignees
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" crash Prefer [crash-on-valid] or [crash-on-invalid] lambda C++11 lambda expressions

Comments

@13steinj
Copy link

13steinj commented Apr 24, 2024

Found on compiler explorer while playing with https://godbolt.org/z/d8a87z3YK.
When the variable is not templated but the lambda is, instead of segfault, appears to be a rejects-valid (determines that a non-lambda is a lambda): https://godbolt.org/z/fa13nn1qE.
Source of boost-ext/mp for the case of asking "what use would such code have": https://github.com/boost-ext/mp/blob/76149014e223a3371895d9b23d9dbd1a05f6af0b/mp.


Compiler explorer currently uses 28cea99 for "trunk". 18.1.0 succeeds.
Minimal reproduction to get a rejects-valid (seemingly confusing the type of the NTTP in the lambda to be the type of the lambda itself)?

template<auto Pred = []<const char c> {
    (void) static_cast<char>(c);
}> // needs to be dependent to take effect
using broken = decltype(Pred.template operator()<'\0'>());

broken<>* boom;

Minimal reproduction to get a crash dump:

template<typename = void>
static constexpr auto innocuous = []<const char m> {
    return m;
};

template<auto Pred = innocuous<>>
using broken = decltype(Pred.template operator()<'\0'>());

broken<>* boom;

It happens doing the static cast as well here; I just felt that simply returning was "more minimal." In both cases, making the NTTP const felt "more minimal" but I don't believe it's necessary, in case clang devs feel the opposite.

Crash Dump
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-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 -std=c++23 -Wall -Wextra -Werror -pedantic -pedantic-errors <source>
1.	<source>:9:1: at annotation token
2.	<source>:2:35: instantiating function definition '(anonymous class)::operator()<'\x00'>'
 #0 0x00000000036be7c8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x36be7c8)
 #1 0x00000000036bc914 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x36bc914)
 #2 0x0000000003605828 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007ee49c642520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x00000000067de6b6 clang::Sema::BuildExpressionFromDeclTemplateArgument(clang::TemplateArgument const&, clang::QualType, clang::SourceLocation) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x67de6b6)
 #5 0x00000000067deb63 clang::Sema::BuildExpressionFromNonTypeTemplateArgument(clang::TemplateArgument const&, clang::SourceLocation) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x67deb63)
 #6 0x000000000698330b (anonymous namespace)::TemplateInstantiator::transformNonTypeTemplateParmRef(clang::Decl*, clang::NonTypeTemplateParmDecl const*, clang::SourceLocation, clang::TemplateArgument, std::optional<unsigned int>) SemaTemplateInstantiate.cpp:0:0
 #7 0x0000000006971ebc clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformExpr(clang::Expr*) SemaTemplateInstantiate.cpp:0:0
 #8 0x00000000069ab55e clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformCXXStaticCastExpr(clang::CXXStaticCastExpr*) SemaTemplateInstantiate.cpp:0:0
 #9 0x000000000697118a clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformExpr(clang::Expr*) SemaTemplateInstantiate.cpp:0:0
#10 0x00000000069a17ee clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformCStyleCastExpr(clang::CStyleCastExpr*) SemaTemplateInstantiate.cpp:0:0
#11 0x000000000697114e clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformExpr(clang::Expr*) SemaTemplateInstantiate.cpp:0:0
#12 0x00000000069a3cb1 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformStmt(clang::Stmt*, clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::StmtDiscardKind) SemaTemplateInstantiate.cpp:0:0
#13 0x00000000069a4cab clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformCompoundStmt(clang::CompoundStmt*, bool) SemaTemplateInstantiate.cpp:0:0
#14 0x00000000069aad91 clang::Sema::SubstStmt(clang::Stmt*, clang::MultiLevelTemplateArgumentList const&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x69aad91)
#15 0x00000000069f6c96 clang::Sema::InstantiateFunctionDefinition(clang::SourceLocation, clang::FunctionDecl*, bool, bool, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x69f6c96)
#16 0x0000000005f559f1 clang::Sema::runWithSufficientStackSpace(clang::SourceLocation, llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5f559f1)
#17 0x00000000068ec1a1 clang::Sema::DeduceReturnType(clang::FunctionDecl*, clang::SourceLocation, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x68ec1a1)
#18 0x000000000634e667 clang::Sema::DiagnoseUseOfDecl(clang::NamedDecl*, llvm::ArrayRef<clang::SourceLocation>, clang::ObjCInterfaceDecl const*, bool, bool, clang::ObjCInterfaceDecl*, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x634e667)
#19 0x000000000673d0ca clang::Sema::BuildCallToMemberFunction(clang::Scope*, clang::Expr*, clang::SourceLocation, llvm::MutableArrayRef<clang::Expr*>, clang::SourceLocation, clang::Expr*, bool, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x673d0ca)
#20 0x00000000063c2074 clang::Sema::BuildCallExpr(clang::Scope*, clang::Expr*, clang::SourceLocation, llvm::MutableArrayRef<clang::Expr*>, clang::SourceLocation, clang::Expr*, bool, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x63c2074)
#21 0x00000000063c885c clang::Sema::ActOnCallExpr(clang::Scope*, clang::Expr*, clang::SourceLocation, llvm::MutableArrayRef<clang::Expr*>, clang::SourceLocation, clang::Expr*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x63c885c)
#22 0x000000000697ae17 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformCallExpr(clang::CallExpr*) SemaTemplateInstantiate.cpp:0:0
#23 0x000000000697113a clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformExpr(clang::Expr*) SemaTemplateInstantiate.cpp:0:0
#24 0x000000000697d05a clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformType(clang::TypeLocBuilder&, clang::TypeLoc) SemaTemplateInstantiate.cpp:0:0
#25 0x0000000006981a3b clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformType(clang::TypeSourceInfo*) SemaTemplateInstantiate.cpp:0:0
#26 0x0000000006983b61 clang::Sema::SubstType(clang::QualType, clang::MultiLevelTemplateArgumentList const&, clang::SourceLocation, clang::DeclarationName) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x6983b61)
#27 0x00000000068147c2 clang::Sema::CheckTemplateIdType(clang::TemplateName, clang::SourceLocation, clang::TemplateArgumentListInfo&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x68147c2)
#28 0x00000000068173d7 clang::Sema::ActOnTemplateIdType(clang::Scope*, clang::CXXScopeSpec&, clang::SourceLocation, clang::OpaquePtr<clang::TemplateName>, clang::IdentifierInfo const*, clang::SourceLocation, clang::SourceLocation, llvm::MutableArrayRef<clang::ParsedTemplateArgument>, clang::SourceLocation, bool, bool, clang::ImplicitTypenameContext) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x68173d7)
#29 0x0000000005f00c67 clang::Parser::AnnotateTemplateIdTokenAsType(clang::CXXScopeSpec&, clang::ImplicitTypenameContext, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5f00c67)
#30 0x0000000005e2a994 clang::Parser::ParseDeclarationSpecifiers(clang::DeclSpec&, clang::Parser::ParsedTemplateInfo const&, clang::AccessSpecifier, clang::Parser::DeclSpecContext, clang::Parser::LateParsedAttrList*, clang::ImplicitTypenameContext) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5e2a994)
#31 0x0000000005deb047 clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5deb047)
#32 0x0000000005debfc3 clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5debfc3)
#33 0x0000000005df4672 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5df4672)
#34 0x0000000005df61e7 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5df61e7)
#35 0x0000000005de51da clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5de51da)
#36 0x0000000003f24df5 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3f24df5)
#37 0x00000000041bc611 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-trunk/bin/clang+++0x41bc611)
#38 0x0000000004141ddb clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4141ddb)
#39 0x000000000429fd73 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x429fd73)
#40 0x0000000000c5468c cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0xc5468c)
#41 0x0000000000c4e63d ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#42 0x0000000003f6dcd9 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
#43 0x0000000003605c53 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3605c53)
#44 0x0000000003f6def9 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
#45 0x0000000003f34447 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3f34447)
#46 0x0000000003f34dfd clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3f34dfd)
#47 0x0000000003f3ec1c clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3f3ec1c)
#48 0x0000000000c51af1 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0xc51af1)
#49 0x0000000000b34794 main (/opt/compiler-explorer/clang-trunk/bin/clang+++0xb34794)
#50 0x00007ee49c629d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#51 0x00007ee49c629e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#52 0x0000000000c4e19e _start (/opt/compiler-explorer/clang-trunk/bin/clang+++0xc4e19e)
clang++: error: clang frontend command failed with exit code 139 (use -v to see invocation)
Compiler returned: 139

In case it gives a hint, -Wunused-variable (no crash, no rejects valid) in this variation in "trunk" but not 18.1.0:

template<auto Pred = []<const char m> {
    return m;
}>
using broken = decltype(Pred.template operator()<'\0'>());

broken<>* boom;
@github-actions github-actions bot added the clang Clang issues not falling into any other category label Apr 24, 2024
@EugeneZelenko EugeneZelenko added clang:frontend Language frontend issues, e.g. anything involving "Sema" crash Prefer [crash-on-valid] or [crash-on-invalid] and removed clang Clang issues not falling into any other category labels Apr 24, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Apr 24, 2024

@llvm/issue-subscribers-clang-frontend

Author: None (13steinj)

Found on compiler explorer while playing with https://godbolt.org/z/d8a87z3YK. When the variable is not templated but the lambda is, instead of segfault, appears to be a rejects-valid (determines that a non-lambda is a lambda): https://godbolt.org/z/fa13nn1qE. Source of boost-ext/mp for the case of asking "what use would such code have": https://github.com/boost-ext/mp/blob/76149014e223a3371895d9b23d9dbd1a05f6af0b/mp.

Compiler explorer currently uses 28cea99 for "trunk". 18.1.0 succeeds.
Minimal reproduction to get a rejects-valid (seemingly confusing the type of the NTTP in the lambda to be the type of the lambda itself)?

template&lt;auto Pred = []&lt;const char c&gt; {
    (void) static_cast&lt;char&gt;(c);
}&gt; // needs to be dependent to take effect
using broken = decltype(Pred.template operator()&lt;'\0'&gt;());

broken&lt;&gt;* boom;

Minimal reproduction to get a crash dump:

template&lt;typename = void&gt;
static constexpr auto innocuous = []&lt;const char m&gt; {
    return m;
};

template&lt;auto Pred = innocuous&lt;&gt;&gt;
using broken = decltype(Pred.template operator()&lt;'\0'&gt;());

broken&lt;&gt;* boom;

It happens doing the static cast as well here; I just felt that simply returning was "more minimal." In both cases, making the NTTP const felt "more minimal" but I don't believe it's necessary, in case clang devs feel the opposite.

<details>
<summary>Crash Dump</summary>

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-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 -std=c++23 -Wall -Wextra -Werror -pedantic -pedantic-errors &lt;source&gt;
1.	&lt;source&gt;:9:1: at annotation token
2.	&lt;source&gt;:2:35: instantiating function definition '(anonymous class)::operator()&lt;'\x00'&gt;'
 #<!-- -->0 0x00000000036be7c8 llvm::sys::PrintStackTrace(llvm::raw_ostream&amp;, int) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x36be7c8)
 #<!-- -->1 0x00000000036bc914 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x36bc914)
 #<!-- -->2 0x0000000003605828 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #<!-- -->3 0x00007ee49c642520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #<!-- -->4 0x00000000067de6b6 clang::Sema::BuildExpressionFromDeclTemplateArgument(clang::TemplateArgument const&amp;, clang::QualType, clang::SourceLocation) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x67de6b6)
 #<!-- -->5 0x00000000067deb63 clang::Sema::BuildExpressionFromNonTypeTemplateArgument(clang::TemplateArgument const&amp;, clang::SourceLocation) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x67deb63)
 #<!-- -->6 0x000000000698330b (anonymous namespace)::TemplateInstantiator::transformNonTypeTemplateParmRef(clang::Decl*, clang::NonTypeTemplateParmDecl const*, clang::SourceLocation, clang::TemplateArgument, std::optional&lt;unsigned int&gt;) SemaTemplateInstantiate.cpp:0:0
 #<!-- -->7 0x0000000006971ebc clang::TreeTransform&lt;(anonymous namespace)::TemplateInstantiator&gt;::TransformExpr(clang::Expr*) SemaTemplateInstantiate.cpp:0:0
 #<!-- -->8 0x00000000069ab55e clang::TreeTransform&lt;(anonymous namespace)::TemplateInstantiator&gt;::TransformCXXStaticCastExpr(clang::CXXStaticCastExpr*) SemaTemplateInstantiate.cpp:0:0
 #<!-- -->9 0x000000000697118a clang::TreeTransform&lt;(anonymous namespace)::TemplateInstantiator&gt;::TransformExpr(clang::Expr*) SemaTemplateInstantiate.cpp:0:0
#<!-- -->10 0x00000000069a17ee clang::TreeTransform&lt;(anonymous namespace)::TemplateInstantiator&gt;::TransformCStyleCastExpr(clang::CStyleCastExpr*) SemaTemplateInstantiate.cpp:0:0
#<!-- -->11 0x000000000697114e clang::TreeTransform&lt;(anonymous namespace)::TemplateInstantiator&gt;::TransformExpr(clang::Expr*) SemaTemplateInstantiate.cpp:0:0
#<!-- -->12 0x00000000069a3cb1 clang::TreeTransform&lt;(anonymous namespace)::TemplateInstantiator&gt;::TransformStmt(clang::Stmt*, clang::TreeTransform&lt;(anonymous namespace)::TemplateInstantiator&gt;::StmtDiscardKind) SemaTemplateInstantiate.cpp:0:0
#<!-- -->13 0x00000000069a4cab clang::TreeTransform&lt;(anonymous namespace)::TemplateInstantiator&gt;::TransformCompoundStmt(clang::CompoundStmt*, bool) SemaTemplateInstantiate.cpp:0:0
#<!-- -->14 0x00000000069aad91 clang::Sema::SubstStmt(clang::Stmt*, clang::MultiLevelTemplateArgumentList const&amp;) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x69aad91)
#<!-- -->15 0x00000000069f6c96 clang::Sema::InstantiateFunctionDefinition(clang::SourceLocation, clang::FunctionDecl*, bool, bool, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x69f6c96)
#<!-- -->16 0x0000000005f559f1 clang::Sema::runWithSufficientStackSpace(clang::SourceLocation, llvm::function_ref&lt;void ()&gt;) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5f559f1)
#<!-- -->17 0x00000000068ec1a1 clang::Sema::DeduceReturnType(clang::FunctionDecl*, clang::SourceLocation, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x68ec1a1)
#<!-- -->18 0x000000000634e667 clang::Sema::DiagnoseUseOfDecl(clang::NamedDecl*, llvm::ArrayRef&lt;clang::SourceLocation&gt;, clang::ObjCInterfaceDecl const*, bool, bool, clang::ObjCInterfaceDecl*, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x634e667)
#<!-- -->19 0x000000000673d0ca clang::Sema::BuildCallToMemberFunction(clang::Scope*, clang::Expr*, clang::SourceLocation, llvm::MutableArrayRef&lt;clang::Expr*&gt;, clang::SourceLocation, clang::Expr*, bool, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x673d0ca)
#<!-- -->20 0x00000000063c2074 clang::Sema::BuildCallExpr(clang::Scope*, clang::Expr*, clang::SourceLocation, llvm::MutableArrayRef&lt;clang::Expr*&gt;, clang::SourceLocation, clang::Expr*, bool, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x63c2074)
#<!-- -->21 0x00000000063c885c clang::Sema::ActOnCallExpr(clang::Scope*, clang::Expr*, clang::SourceLocation, llvm::MutableArrayRef&lt;clang::Expr*&gt;, clang::SourceLocation, clang::Expr*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x63c885c)
#<!-- -->22 0x000000000697ae17 clang::TreeTransform&lt;(anonymous namespace)::TemplateInstantiator&gt;::TransformCallExpr(clang::CallExpr*) SemaTemplateInstantiate.cpp:0:0
#<!-- -->23 0x000000000697113a clang::TreeTransform&lt;(anonymous namespace)::TemplateInstantiator&gt;::TransformExpr(clang::Expr*) SemaTemplateInstantiate.cpp:0:0
#<!-- -->24 0x000000000697d05a clang::TreeTransform&lt;(anonymous namespace)::TemplateInstantiator&gt;::TransformType(clang::TypeLocBuilder&amp;, clang::TypeLoc) SemaTemplateInstantiate.cpp:0:0
#<!-- -->25 0x0000000006981a3b clang::TreeTransform&lt;(anonymous namespace)::TemplateInstantiator&gt;::TransformType(clang::TypeSourceInfo*) SemaTemplateInstantiate.cpp:0:0
#<!-- -->26 0x0000000006983b61 clang::Sema::SubstType(clang::QualType, clang::MultiLevelTemplateArgumentList const&amp;, clang::SourceLocation, clang::DeclarationName) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x6983b61)
#<!-- -->27 0x00000000068147c2 clang::Sema::CheckTemplateIdType(clang::TemplateName, clang::SourceLocation, clang::TemplateArgumentListInfo&amp;) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x68147c2)
#<!-- -->28 0x00000000068173d7 clang::Sema::ActOnTemplateIdType(clang::Scope*, clang::CXXScopeSpec&amp;, clang::SourceLocation, clang::OpaquePtr&lt;clang::TemplateName&gt;, clang::IdentifierInfo const*, clang::SourceLocation, clang::SourceLocation, llvm::MutableArrayRef&lt;clang::ParsedTemplateArgument&gt;, clang::SourceLocation, bool, bool, clang::ImplicitTypenameContext) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x68173d7)
#<!-- -->29 0x0000000005f00c67 clang::Parser::AnnotateTemplateIdTokenAsType(clang::CXXScopeSpec&amp;, clang::ImplicitTypenameContext, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5f00c67)
#<!-- -->30 0x0000000005e2a994 clang::Parser::ParseDeclarationSpecifiers(clang::DeclSpec&amp;, clang::Parser::ParsedTemplateInfo const&amp;, clang::AccessSpecifier, clang::Parser::DeclSpecContext, clang::Parser::LateParsedAttrList*, clang::ImplicitTypenameContext) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5e2a994)
#<!-- -->31 0x0000000005deb047 clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&amp;, clang::ParsedAttributes&amp;, clang::ParsingDeclSpec&amp;, clang::AccessSpecifier) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5deb047)
#<!-- -->32 0x0000000005debfc3 clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&amp;, clang::ParsedAttributes&amp;, clang::ParsingDeclSpec*, clang::AccessSpecifier) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5debfc3)
#<!-- -->33 0x0000000005df4672 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&amp;, clang::ParsedAttributes&amp;, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5df4672)
#<!-- -->34 0x0000000005df61e7 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr&lt;clang::DeclGroupRef&gt;&amp;, clang::Sema::ModuleImportState&amp;) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5df61e7)
#<!-- -->35 0x0000000005de51da clang::ParseAST(clang::Sema&amp;, bool, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5de51da)
#<!-- -->36 0x0000000003f24df5 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3f24df5)
#<!-- -->37 0x00000000041bc611 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-trunk/bin/clang+++0x41bc611)
#<!-- -->38 0x0000000004141ddb clang::CompilerInstance::ExecuteAction(clang::FrontendAction&amp;) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4141ddb)
#<!-- -->39 0x000000000429fd73 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x429fd73)
#<!-- -->40 0x0000000000c5468c cc1_main(llvm::ArrayRef&lt;char const*&gt;, char const*, void*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0xc5468c)
#<!-- -->41 0x0000000000c4e63d ExecuteCC1Tool(llvm::SmallVectorImpl&lt;char const*&gt;&amp;, llvm::ToolContext const&amp;) driver.cpp:0:0
#<!-- -->42 0x0000000003f6dcd9 void llvm::function_ref&lt;void ()&gt;::callback_fn&lt;clang::driver::CC1Command::Execute(llvm::ArrayRef&lt;std::optional&lt;llvm::StringRef&gt;&gt;, std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt;&gt;*, bool*) const::'lambda'()&gt;(long) Job.cpp:0:0
#<!-- -->43 0x0000000003605c53 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref&lt;void ()&gt;) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3605c53)
#<!-- -->44 0x0000000003f6def9 clang::driver::CC1Command::Execute(llvm::ArrayRef&lt;std::optional&lt;llvm::StringRef&gt;&gt;, std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt;&gt;*, bool*) const (.part.0) Job.cpp:0:0
#<!-- -->45 0x0000000003f34447 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&amp;, clang::driver::Command const*&amp;, bool) const (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3f34447)
#<!-- -->46 0x0000000003f34dfd clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&amp;, llvm::SmallVectorImpl&lt;std::pair&lt;int, clang::driver::Command const*&gt;&gt;&amp;, bool) const (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3f34dfd)
#<!-- -->47 0x0000000003f3ec1c clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&amp;, llvm::SmallVectorImpl&lt;std::pair&lt;int, clang::driver::Command const*&gt;&gt;&amp;) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3f3ec1c)
#<!-- -->48 0x0000000000c51af1 clang_main(int, char**, llvm::ToolContext const&amp;) (/opt/compiler-explorer/clang-trunk/bin/clang+++0xc51af1)
#<!-- -->49 0x0000000000b34794 main (/opt/compiler-explorer/clang-trunk/bin/clang+++0xb34794)
#<!-- -->50 0x00007ee49c629d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#<!-- -->51 0x00007ee49c629e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#<!-- -->52 0x0000000000c4e19e _start (/opt/compiler-explorer/clang-trunk/bin/clang+++0xc4e19e)
clang++: error: clang frontend command failed with exit code 139 (use -v to see invocation)
Compiler returned: 139

</details>

In case it gives a hint, -Wunused-variable (no crash, no rejects valid) in this variation in "trunk" but not 18.1.0:

template&lt;auto Pred = []&lt;const char m&gt; {
    return m;
}&gt;
using broken = decltype(Pred.template operator()&lt;'\0'&gt;());

broken&lt;&gt;* boom;

@zyn0217 zyn0217 self-assigned this Apr 24, 2024
@zyn0217
Copy link
Contributor

zyn0217 commented Apr 24, 2024

Thanks for the report! This is a regression from my recent patch #82310. However, I've come up with a fix and will submit the patch in a moment.

@13steinj
Copy link
Author

tyvm for the quick response + triage!

Also, apologies if my crash dump auto-referenced a slew of GH issues before! Something with the way GH parses markdown made it so that without a blank line it wasn't treated as a code-block. I edited to add the line but don't know if references get removed if edited.

zyn0217 added a commit that referenced this issue Aug 27, 2024
…late decl (#89934)

In the last patch #82310, we used template depths to tell if such alias
decls contain lambdas, which is wrong because the lambda can also appear
as a part of the default argument, and that would make
`getTemplateInstantiationArgs` provide extra template arguments in
undesired contexts. This leads to issue #89853.

Moreover, our approach
for #82104 was sadly wrong.
We tried to teach `DeduceReturnType` to consider alias template
arguments; however, giving these arguments in the context where they
should have been substituted in a `TransformCallExpr` call is never
correct.

This patch addresses such problems by using a `RecursiveASTVisitor` to
check if the lambda is contained by an alias `Decl`, as well as
twiddling the lambda dependencies - we should also build a dependent
lambda expression if the surrounding alias template arguments were
dependent.

Fixes #89853
Fixes #102760
Fixes #105885
llvmbot pushed a commit to llvmbot/llvm-project that referenced this issue Aug 27, 2024
…late decl (llvm#89934)

In the last patch llvm#82310, we used template depths to tell if such alias
decls contain lambdas, which is wrong because the lambda can also appear
as a part of the default argument, and that would make
`getTemplateInstantiationArgs` provide extra template arguments in
undesired contexts. This leads to issue llvm#89853.

Moreover, our approach
for llvm#82104 was sadly wrong.
We tried to teach `DeduceReturnType` to consider alias template
arguments; however, giving these arguments in the context where they
should have been substituted in a `TransformCallExpr` call is never
correct.

This patch addresses such problems by using a `RecursiveASTVisitor` to
check if the lambda is contained by an alias `Decl`, as well as
twiddling the lambda dependencies - we should also build a dependent
lambda expression if the surrounding alias template arguments were
dependent.

Fixes llvm#89853
Fixes llvm#102760
Fixes llvm#105885

(cherry picked from commit b412ec5)
5c4lar pushed a commit to 5c4lar/llvm-project that referenced this issue Aug 29, 2024
…late decl (llvm#89934)

In the last patch llvm#82310, we used template depths to tell if such alias
decls contain lambdas, which is wrong because the lambda can also appear
as a part of the default argument, and that would make
`getTemplateInstantiationArgs` provide extra template arguments in
undesired contexts. This leads to issue llvm#89853.

Moreover, our approach
for llvm#82104 was sadly wrong.
We tried to teach `DeduceReturnType` to consider alias template
arguments; however, giving these arguments in the context where they
should have been substituted in a `TransformCallExpr` call is never
correct.

This patch addresses such problems by using a `RecursiveASTVisitor` to
check if the lambda is contained by an alias `Decl`, as well as
twiddling the lambda dependencies - we should also build a dependent
lambda expression if the surrounding alias template arguments were
dependent.

Fixes llvm#89853
Fixes llvm#102760
Fixes llvm#105885
tru pushed a commit to llvmbot/llvm-project that referenced this issue Sep 1, 2024
…late decl (llvm#89934)

In the last patch llvm#82310, we used template depths to tell if such alias
decls contain lambdas, which is wrong because the lambda can also appear
as a part of the default argument, and that would make
`getTemplateInstantiationArgs` provide extra template arguments in
undesired contexts. This leads to issue llvm#89853.

Moreover, our approach
for llvm#82104 was sadly wrong.
We tried to teach `DeduceReturnType` to consider alias template
arguments; however, giving these arguments in the context where they
should have been substituted in a `TransformCallExpr` call is never
correct.

This patch addresses such problems by using a `RecursiveASTVisitor` to
check if the lambda is contained by an alias `Decl`, as well as
twiddling the lambda dependencies - we should also build a dependent
lambda expression if the surrounding alias template arguments were
dependent.

Fixes llvm#89853
Fixes llvm#102760
Fixes llvm#105885

(cherry picked from commit b412ec5)
dmpolukhin pushed a commit to dmpolukhin/llvm-project that referenced this issue Sep 2, 2024
…late decl (llvm#89934)

In the last patch llvm#82310, we used template depths to tell if such alias
decls contain lambdas, which is wrong because the lambda can also appear
as a part of the default argument, and that would make
`getTemplateInstantiationArgs` provide extra template arguments in
undesired contexts. This leads to issue llvm#89853.

Moreover, our approach
for llvm#82104 was sadly wrong.
We tried to teach `DeduceReturnType` to consider alias template
arguments; however, giving these arguments in the context where they
should have been substituted in a `TransformCallExpr` call is never
correct.

This patch addresses such problems by using a `RecursiveASTVisitor` to
check if the lambda is contained by an alias `Decl`, as well as
twiddling the lambda dependencies - we should also build a dependent
lambda expression if the surrounding alias template arguments were
dependent.

Fixes llvm#89853
Fixes llvm#102760
Fixes llvm#105885
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" crash Prefer [crash-on-valid] or [crash-on-invalid] lambda C++11 lambda expressions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants