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++ crash with templated lambdas #53934

Closed
ajrh1 opened this issue Feb 18, 2022 · 4 comments
Closed

clang++ crash with templated lambdas #53934

ajrh1 opened this issue Feb 18, 2022 · 4 comments
Labels
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

@ajrh1
Copy link

ajrh1 commented Feb 18, 2022

https://godbolt.org/z/bnG1xn57n

below c-reduced testcase, appears to compile and run fine with gcc and msvc latest, but crashes clang releases and trunk

int main() {
    int n = 1;
    auto h = [&]<int>() { n = 0; };
    auto m = [h]<int j>() { h.template operator()<j>(); };
    m.template operator()<0>();
    return n;
}

clang version 15.0.0 (https://github.com/llvm/llvm-project.git d9da6a5)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /opt/compiler-explorer/clang-trunk/bin
Found candidate GCC installation: /opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/12.0.1
Selected GCC installation: /opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/12.0.1
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Candidate multilib: x32;@MX32
Selected multilib: .;@m64
(in-process)
"/opt/compiler-explorer/clang-trunk-20220218/bin/clang-15" -cc1 -triple x86_64-unknown-linux-gnu -S -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name example.cpp -mrelocation-model static -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -mllvm -treat-scalable-fixed-error-as-warning -debug-info-kind=constructor -dwarf-version=5 -debugger-tuning=gdb -v -fcoverage-compilation-dir=/app -resource-dir /opt/compiler-explorer/clang-trunk-20220218/lib/clang/15.0.0 -internal-isystem /opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/12.0.1/../../../../include/c++/12.0.1 -internal-isystem /opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/12.0.1/../../../../include/c++/12.0.1/x86_64-linux-gnu -internal-isystem /opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/12.0.1/../../../../include/c++/12.0.1/backward -internal-isystem /opt/compiler-explorer/clang-trunk-20220218/lib/clang/15.0.0/include -internal-isystem /usr/local/include -internal-isystem /opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/12.0.1/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -std=c++20 -fdeprecated-macro -fdebug-compilation-dir=/app -ferror-limit 19 -fgnuc-version=4.2.1 -fno-implicit-modules -fcxx-exceptions -fexceptions -fcolor-diagnostics -mllvm --x86-asm-syntax=intel -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /app/output.s -x c++
clang -cc1 version 15.0.0 based upon LLVM 15.0.0git default target x86_64-unknown-linux-gnu
ignoring nonexistent directory "/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/12.0.1/../../../../x86_64-linux-gnu/include"
ignoring nonexistent directory "/include"
#include "..." search starts here:
#include <...> search starts here:
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/12.0.1/../../../../include/c++/12.0.1
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/12.0.1/../../../../include/c++/12.0.1/x86_64-linux-gnu
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/12.0.1/../../../../include/c++/12.0.1/backward
/opt/compiler-explorer/clang-trunk-20220218/lib/clang/15.0.0/include
/usr/local/include
/usr/include/x86_64-linux-gnu
/usr/include
End of search list.
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++ -g -o /app/output.s -mllvm --x86-asm-syntax=intel -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics -v -std=c++20

  1. :5:30: current parser token ')'
  2. :1:12: parsing function body 'main'
  3. :1:12: in compound statement ('{}')
  4. :4:14: instantiating function definition 'main()::(anonymous class)::operator()<0>'
  5. :3:14: instantiating class definition ''

#0 0x00005610e65bd42f PrintStackTraceSignalHandler(void*) Signals.cpp:0:0
#1 0x00005610e65bb300 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x35bb300)
#2 0x00005610e64f5088 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#3 0x00007f608c9153c0 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x153c0)
#4 0x00005610e8bed6de clang::Sema::SubstFunctionDeclType(clang::TypeSourceInfo*, clang::MultiLevelTemplateArgumentList const&, clang::SourceLocation, clang::DeclarationName, clang::CXXRecordDecl*, clang::Qualifiers) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5bed6de)
#5 0x00005610e8bfe4b0 clang::TemplateDeclInstantiator::SubstFunctionType(clang::FunctionDecl*, llvm::SmallVectorImplclang::ParmVarDecl*&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5bfe4b0)
#6 0x00005610e8c3a706 clang::TemplateDeclInstantiator::VisitCXXMethodDecl(clang::CXXMethodDecl*, clang::TemplateParameterList*, llvm::Optional<clang::ASTTemplateArgumentListInfo const*>, clang::TemplateDeclInstantiator::RewriteKind) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5c3a706)
#7 0x00005610e8be2bc7 clang::Sema::InstantiateClass(clang::SourceLocation, clang::CXXRecordDecl*, clang::CXXRecordDecl*, clang::MultiLevelTemplateArgumentList const&, clang::TemplateSpecializationKind, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5be2bc7)
#8 0x00005610e8c3a264 clang::TemplateDeclInstantiator::VisitCXXRecordDecl(clang::CXXRecordDecl*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5c3a264)
#9 0x00005610e8c3bfc4 void llvm::function_ref<void ()>::callback_fn<clang::Sema::SubstDecl(clang::Decl*, clang::DeclContext*, clang::MultiLevelTemplateArgumentList const&)::'lambda'()>(long) SemaTemplateInstantiateDecl.cpp:0:0
#10 0x00005610e84fb69f clang::Sema::runWithSufficientStackSpace(clang::SourceLocation, llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x54fb69f)
#11 0x00005610e8bfdf93 clang::Sema::SubstDecl(clang::Decl*, clang::DeclContext*, clang::MultiLevelTemplateArgumentList const&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5bfdf93)
#12 0x00005610e8c2cade clang::Sema::FindInstantiatedDecl(clang::SourceLocation, clang::NamedDecl*, clang::MultiLevelTemplateArgumentList const&, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5c2cade)
#13 0x00005610e8bc0a0b (anonymous namespace)::TemplateInstantiator::TransformDecl(clang::SourceLocation, clang::Decl*) SemaTemplateInstantiate.cpp:0:0
#14 0x00005610e8be5024 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformUnresolvedMemberExpr(clang::UnresolvedMemberExpr*) SemaTemplateInstantiate.cpp:0:0
#15 0x00005610e8bcd9ef clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformExpr(clang::Expr*) SemaTemplateInstantiate.cpp:0:0
#16 0x00005610e8bd4cd7 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformCallExpr(clang::CallExpr*) SemaTemplateInstantiate.cpp:0:0
#17 0x00005610e8bcd593 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformExpr(clang::Expr*) SemaTemplateInstantiate.cpp:0:0
#18 0x00005610e8bf4ec0 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformStmt(clang::Stmt*, clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::StmtDiscardKind) SemaTemplateInstantiate.cpp:0:0
#19 0x00005610e8bf60b3 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformCompoundStmt(clang::CompoundStmt*, bool) SemaTemplateInstantiate.cpp:0:0
#20 0x00005610e8bfa6ca clang::Sema::SubstStmt(clang::Stmt*, clang::MultiLevelTemplateArgumentList const&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5bfa6ca)
#21 0x00005610e8c32027 clang::Sema::InstantiateFunctionDefinition(clang::SourceLocation, clang::FunctionDecl*, bool, bool, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5c32027)
#22 0x00005610e84fb69f clang::Sema::runWithSufficientStackSpace(clang::SourceLocation, llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x54fb69f)
#23 0x00005610e8b6ab2d clang::Sema::DeduceReturnType(clang::FunctionDecl*, clang::SourceLocation, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5b6ab2d)
#24 0x00005610e87a3e87 clang::Sema::DiagnoseUseOfDecl(clang::NamedDecl*, llvm::ArrayRefclang::SourceLocation, clang::ObjCInterfaceDecl const*, bool, bool, clang::ObjCInterfaceDecl*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x57a3e87)
#25 0x00005610e8a78070 clang::Sema::BuildCallToMemberFunction(clang::Scope*, clang::Expr*, clang::SourceLocation, llvm::MutableArrayRefclang::Expr*, clang::SourceLocation, clang::Expr*, bool, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5a78070)
#26 0x00005610e87dc056 clang::Sema::BuildCallExpr(clang::Scope*, clang::Expr*, clang::SourceLocation, llvm::MutableArrayRefclang::Expr*, clang::SourceLocation, clang::Expr*, bool, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x57dc056)
#27 0x00005610e87e1054 clang::Sema::ActOnCallExpr(clang::Scope*, clang::Expr*, clang::SourceLocation, llvm::MutableArrayRefclang::Expr*, clang::SourceLocation, clang::Expr*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x57e1054)
#28 0x00005610e843d4ab clang::Parser::ParsePostfixExpressionSuffix(clang::ActionResult<clang::Expr*, true>) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x543d4ab)
#29 0x00005610e84376b7 clang::Parser::ParseCastExpression(clang::Parser::CastParseKind, bool, bool&, clang::Parser::TypeCastState, bool, bool*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x54376b7)
#30 0x00005610e843a0d6 clang::Parser::ParseCastExpression(clang::Parser::CastParseKind, bool, clang::Parser::TypeCastState, bool, bool*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x543a0d6)
#31 0x00005610e843a168 clang::Parser::ParseAssignmentExpression(clang::Parser::TypeCastState) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x543a168)
#32 0x00005610e843ae79 clang::Parser::ParseExpression(clang::Parser::TypeCastState) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x543ae79)
#33 0x00005610e84a311d clang::Parser::ParseExprStatement(clang::Parser::ParsedStmtContext) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x54a311d)
#34 0x00005610e849c0db clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::ParsedAttributesWithRange&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x549c0db)
#35 0x00005610e849d01d clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x549d01d)
#36 0x00005610e8497ef2 clang::Parser::ParseCompoundStatementBody(bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5497ef2)
#37 0x00005610e8498d93 clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5498d93)
#38 0x00005610e83eccda clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x53eccda)
#39 0x00005610e841654c clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x541654c)
#40 0x00005610e83e7fa9 clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributesWithRange&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x53e7fa9)
#41 0x00005610e83e86b1 clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributesWithRange&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (.part.280) Parser.cpp:0:0
#42 0x00005610e83eeaa9 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributesWithRange&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x53eeaa9)
#43 0x00005610e83efa69 clang::Parser::ParseTopLevelDecl(clang::OpaquePtrclang::DeclGroupRef&, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x53efa69)
#44 0x00005610e83eff65 clang::Parser::ParseFirstTopLevelDecl(clang::OpaquePtrclang::DeclGroupRef&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x53eff65)
#45 0x00005610e83e3263 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x53e3263)
#46 0x00005610e756f4a2 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-trunk/bin/clang+++0x456f4a2)
#47 0x00005610e6f6d1c1 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3f6d1c1)
#48 0x00005610e6f07902 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3f07902)
#49 0x00005610e70392a3 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x40392a3)
#50 0x00005610e41b3604 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x11b3604)
#51 0x00005610e41af5bd ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&) driver.cpp:0:0
#52 0x00005610e6da3a05 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optionalllvm::StringRef >, std::__cxx11::basic_string<char, std::char_traits, std::allocator >, bool) const::'lambda'()>(long) Job.cpp:0:0
#53 0x00005610e64f5673 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x34f5673)
#54 0x00005610e6da5ad8 clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optionalllvm::StringRef >, std::__cxx11::basic_string<char, std::char_traits, std::allocator >, bool) const (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3da5ad8)
#55 0x00005610e6d78f0a clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&) const (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3d78f0a)
#56 0x00005610e6d79a4f 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+++0x3d79a4f)
#57 0x00005610e6d82415 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*> >&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3d82415)
#58 0x00005610e40bf362 main (/opt/compiler-explorer/clang-trunk/bin/clang+++0x10bf362)
#59 0x00007f608c3c50b3 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b3)
#60 0x00005610e41af13a _start (/opt/compiler-explorer/clang-trunk/bin/clang+++0x11af13a)
clang-15: error: clang frontend command failed with exit code 139 (use -v to see invocation)
Compiler returned: 139

A slightly less reduced version of the same code, at least compiles but produces a strange warning

template <typename g> void at(g h) {
    auto m = [h]<int j>() { h.template operator()<j>(); };
    m.template operator()<0>();
}

int main() {
    int n = 1;
    at([&]<int>() { n = 0; });
    return n;
}

<source>:8:8: warning: class '' does not declare any constructor to initialize its non-modifiable members
    at([&]<int>() { n = 0; });
       ^
<source>:8:8: note: in instantiation of member class '' requested here
<source>:3:16: note: in instantiation of function template specialization 'at((lambda at <source>:8:8))::(anonymous class)::operator()<0>' requested here
    m.template operator()<0>();
               ^
<source>:8:5: note: in instantiation of function template specialization 'at<(lambda at <source>:8:8)>' requested here
    at([&]<int>() { n = 0; });
    ^
<source>:8:21: note: reference member '' will never be initialized
    at([&]<int>() { n = 0; });
                    ^
1 warning generated.
@EugeneZelenko EugeneZelenko 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] and removed new issue labels Feb 18, 2022
@llvmbot
Copy link
Collaborator

llvmbot commented Feb 18, 2022

@llvm/issue-subscribers-clang-frontend

@vgvassilev vgvassilev added the good first issue https://github.com/llvm/llvm-project/contribute label Feb 20, 2022
@junaire
Copy link
Member

junaire commented Mar 2, 2022

Ummm, I can't reproduce the case, no matter the assertion build or the release build. I guess somebody may have already fixed this?
https://godbolt.org/z/qxGq8brjq

@VitalyAnkh
Copy link
Contributor

I can’t reproduce the case either. Seems fixed.

@cor3ntin
Copy link
Contributor

Given this is fixed, I'm closing the issue

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" 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

No branches or pull requests

7 participants