Skip to content

[clang] crash on valid in isPackExpansion #116036

@vient

Description

@vient

Minified from real code (minification may not be the best since half of cvise passes crash or fail)

template <bool> using __bool_constant = int;
int invoke;
template <typename>
concept invocable = requires { invoke; };
template <template <typename> typename> struct Walk {
  static void traverse(auto)
    requires invocable<decltype([](auto...) {})>;
};
template <typename> using DoNotPrune = __bool_constant<false>;
template <template <typename> typename Prune = DoNotPrune>
auto for_each_leaf(auto value) {
  Walk<Prune>::traverse(value);
}
auto collect(int value) {
  for_each_leaf(value);
}

compiled with clang++-19 -std=c++23 -o test.o -c test.cpp produces this

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: clang++-19 -std=c++23 -o test.o -c test.cpp
1.      test.cpp:15:22: current parser token ')'
2.      test.cpp:14:25: parsing function body 'collect'
3.      test.cpp:14:25: in compound statement ('{}')
4.      test.cpp:11:6: instantiating function definition 'for_each_leaf<DoNotPrune, int>'
 #0 0x00007f1c43e1cb06 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/usr/lib/llvm-19/bin/../lib/libLLVM.so.19.1+0xea3b06)
 #1 0x00007f1c43e1a7b0 llvm::sys::RunSignalHandlers() (/usr/lib/llvm-19/bin/../lib/libLLVM.so.19.1+0xea17b0)
 #2 0x00007f1c43e1bf64 llvm::sys::CleanupOnSignal(unsigned long) (/usr/lib/llvm-19/bin/../lib/libLLVM.so.19.1+0xea2f64)
 #3 0x00007f1c43d6a6d0 (/usr/lib/llvm-19/bin/../lib/libLLVM.so.19.1+0xdf16d0)
 #4 0x00007f1c4ee28420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #5 0x00007f1c4bd46ffe clang::TemplateArgument::isPackExpansion() const (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x1279ffe)
 #6 0x00007f1c4c86f2ac (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x1da22ac)
 #7 0x00007f1c4c8287c6 clang::Sema::SubstType(clang::TypeLoc, clang::MultiLevelTemplateArgumentList const&, clang::SourceLocation, clang::DeclarationName) (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x1d5b7c6)
 #8 0x00007f1c4c82a81f clang::Sema::SubstParmVarDecl(clang::ParmVarDecl*, clang::MultiLevelTemplateArgumentList const&, int, std::optional<unsigned int>, bool, bool) (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x1d5d81f)
 #9 0x00007f1c4c862f1a (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x1d95f1a)
#10 0x00007f1c4c8662da (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x1d992da)
#11 0x00007f1c4c864e1c (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x1d97e1c)
#12 0x00007f1c4c857f9e (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x1d8af9e)
#13 0x00007f1c4c86a2d7 (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x1d9d2d7)
#14 0x00007f1c4c82865b (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x1d5b65b)
#15 0x00007f1c4c82f565 (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x1d62565)
#16 0x00007f1c4c82fed0 (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x1d62ed0)
#17 0x00007f1c4c859a24 (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x1d8ca24)
#18 0x00007f1c4c8307c2 clang::Sema::SubstConstraintExpr(clang::Expr*, clang::MultiLevelTemplateArgumentList const&) (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x1d637c2)
#19 0x00007f1c4c1811b4 (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x16b41b4)
#20 0x00007f1c4c179ec4 (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x16acec4)
#21 0x00007f1c4c179c5c clang::Sema::CheckConstraintSatisfaction(clang::NamedDecl const*, llvm::ArrayRef<clang::Expr const*>, llvm::SmallVectorImpl<clang::Expr*>&, clang::MultiLevelTemplateArgumentList const&, clang::SourceRange, clang::ConstraintSatisfaction&) (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x16acc5c)
#22 0x00007f1c4c17ce2d clang::Sema::CheckInstantiatedFunctionTemplateConstraints(clang::SourceLocation, clang::FunctionDecl*, llvm::ArrayRef<clang::TemplateArgument>, clang::ConstraintSatisfaction&) (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x16afe2d)
#23 0x00007f1c4c77a4a9 clang::Sema::FinishTemplateArgumentDeduction(clang::FunctionTemplateDecl*, llvm::SmallVectorImpl<clang::DeducedTemplateArgument>&, unsigned int, clang::FunctionDecl*&, clang::sema::TemplateDeductionInfo&, llvm::SmallVectorImpl<clang::Sema::OriginalCallArg> const*, bool, llvm::function_ref<bool ()>) (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x1cad4a9)
#24 0x00007f1c4c7d5bd7 (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x1d08bd7)
#25 0x00007f1c4c0386ed clang::Sema::runWithSufficientStackSpace(clang::SourceLocation, llvm::function_ref<void ()>) (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x156b6ed)
#26 0x00007f1c4c77bf8b clang::Sema::DeduceTemplateArguments(clang::FunctionTemplateDecl*, clang::TemplateArgumentListInfo*, llvm::ArrayRef<clang::Expr*>, clang::FunctionDecl*&, clang::sema::TemplateDeductionInfo&, bool, bool, clang::QualType, clang::Expr::Classification, llvm::function_ref<bool (llvm::ArrayRef<clang::QualType>)>) (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x1caef8b)
#27 0x00007f1c4c663c44 clang::Sema::AddTemplateOverloadCandidate(clang::FunctionTemplateDecl*, clang::DeclAccessPair, clang::TemplateArgumentListInfo*, llvm::ArrayRef<clang::Expr*>, clang::OverloadCandidateSet&, bool, bool, bool, clang::CallExpr::ADLCallKind, clang::OverloadCandidateParamOrder, bool) (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x1b96c44)
#28 0x00007f1c4c6742fc (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x1ba72fc)
#29 0x00007f1c4c6741d0 clang::Sema::AddOverloadedCallCandidates(clang::UnresolvedLookupExpr*, llvm::ArrayRef<clang::Expr*>, clang::OverloadCandidateSet&, bool) (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x1ba71d0)
#30 0x00007f1c4c674510 clang::Sema::buildOverloadedCallSet(clang::Scope*, clang::Expr*, clang::UnresolvedLookupExpr*, llvm::MutableArrayRef<clang::Expr*>, clang::SourceLocation, clang::OverloadCandidateSet*, clang::ActionResult<clang::Expr*, true>*) (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x1ba7510)
#31 0x00007f1c4c674810 clang::Sema::BuildOverloadedCallExpr(clang::Scope*, clang::Expr*, clang::UnresolvedLookupExpr*, clang::SourceLocation, llvm::MutableArrayRef<clang::Expr*>, clang::SourceLocation, clang::Expr*, bool, bool) (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x1ba7810)
#32 0x00007f1c4c32725a clang::Sema::BuildCallExpr(clang::Scope*, clang::Expr*, clang::SourceLocation, llvm::MutableArrayRef<clang::Expr*>, clang::SourceLocation, clang::Expr*, bool, bool) (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x185a25a)
#33 0x00007f1c4c33aa3e clang::Sema::ActOnCallExpr(clang::Scope*, clang::Expr*, clang::SourceLocation, llvm::MutableArrayRef<clang::Expr*>, clang::SourceLocation, clang::Expr*) (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x186da3e)
#34 0x00007f1c4c85a15a (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x1d8d15a)
#35 0x00007f1c4c82ed21 (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x1d61d21)
#36 0x00007f1c4c85f89d (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x1d9289d)
#37 0x00007f1c4c82ecb4 clang::Sema::SubstStmt(clang::Stmt*, clang::MultiLevelTemplateArgumentList const&) (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x1d61cb4)
#38 0x00007f1c4c894b2b clang::Sema::InstantiateFunctionDefinition(clang::SourceLocation, clang::FunctionDecl*, bool, bool, bool) (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x1dc7b2b)
#39 0x00007f1c4c0386ed clang::Sema::runWithSufficientStackSpace(clang::SourceLocation, llvm::function_ref<void ()>) (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x156b6ed)
#40 0x00007f1c4c77f8ff clang::Sema::DeduceReturnType(clang::FunctionDecl*, clang::SourceLocation, bool) (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x1cb28ff)
#41 0x00007f1c4c3223e1 clang::Sema::DiagnoseUseOfDecl(clang::NamedDecl*, llvm::ArrayRef<clang::SourceLocation>, clang::ObjCInterfaceDecl const*, bool, bool, clang::ObjCInterfaceDecl*, bool) (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x18553e1)
#42 0x00007f1c4c674b30 (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x1ba7b30)
#43 0x00007f1c4c67491f clang::Sema::BuildOverloadedCallExpr(clang::Scope*, clang::Expr*, clang::UnresolvedLookupExpr*, clang::SourceLocation, llvm::MutableArrayRef<clang::Expr*>, clang::SourceLocation, clang::Expr*, bool, bool) (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x1ba791f)
#44 0x00007f1c4c32725a clang::Sema::BuildCallExpr(clang::Scope*, clang::Expr*, clang::SourceLocation, llvm::MutableArrayRef<clang::Expr*>, clang::SourceLocation, clang::Expr*, bool, bool) (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x185a25a)
#45 0x00007f1c4c33aa3e clang::Sema::ActOnCallExpr(clang::Scope*, clang::Expr*, clang::SourceLocation, llvm::MutableArrayRef<clang::Expr*>, clang::SourceLocation, clang::Expr*) (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x186da3e)
#46 0x00007f1c4b750e9c clang::Parser::ParsePostfixExpressionSuffix(clang::ActionResult<clang::Expr*, true>) (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0xc83e9c)
#47 0x00007f1c4b754619 clang::Parser::ParseCastExpression(clang::Parser::CastParseKind, bool, bool&, clang::Parser::TypeCastState, bool, bool*) (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0xc87619)
#48 0x00007f1c4b74de59 clang::Parser::ParseAssignmentExpression(clang::Parser::TypeCastState) (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0xc80e59)
#49 0x00007f1c4b74dd29 clang::Parser::ParseExpression(clang::Parser::TypeCastState) (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0xc80d29)
#50 0x00007f1c4b7b5c15 clang::Parser::ParseExprStatement(clang::Parser::ParsedStmtContext) (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0xce8c15)
#51 0x00007f1c4b7b3f30 clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::ParsedAttributes&, clang::ParsedAttributes&) (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0xce6f30)
#52 0x00007f1c4b7b3906 clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*) (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0xce6906)
#53 0x00007f1c4b7bc460 clang::Parser::ParseCompoundStatementBody(bool) (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0xcef460)
#54 0x00007f1c4b7bd582 clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0xcf0582)
#55 0x00007f1c4b7d737f clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0xd0a37f)
#56 0x00007f1c4b719b44 clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::Parser::ParsedTemplateInfo&, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0xc4cb44)
#57 0x00007f1c4b7d63a3 clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0xd093a3)
#58 0x00007f1c4b7d5d5b clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0xd08d5b)
#59 0x00007f1c4b7d4f77 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0xd07f77)
#60 0x00007f1c4b7d3437 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0xd06437)
#61 0x00007f1c4b701efe clang::ParseAST(clang::Sema&, bool, bool) (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0xc34efe)
#62 0x00007f1c4d7a8bb5 clang::FrontendAction::Execute() (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x2cdbbb5)
#63 0x00007f1c4d71e2a4 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x2c512a4)
#64 0x00007f1c4d824c9e clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x2d57c9e)
#65 0x0000560ce11456e0 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/usr/lib/llvm-19/bin/clang+0x116e0)
#66 0x0000560ce11429e5 (/usr/lib/llvm-19/bin/clang+0xe9e5)
#67 0x00007f1c4d3bd9a9 (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x28f09a9)
#68 0x00007f1c43d6a468 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/usr/lib/llvm-19/bin/../lib/libLLVM.so.19.1+0xdf1468)
#69 0x00007f1c4d3bd34d clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x28f034d)
#70 0x00007f1c4d3839a9 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x28b69a9)
#71 0x00007f1c4d383c1e clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x28b6c1e)
#72 0x00007f1c4d3a06fb clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x28d36fb)
#73 0x0000560ce114245f clang_main(int, char**, llvm::ToolContext const&) (/usr/lib/llvm-19/bin/clang+0xe45f)
#74 0x0000560ce114f706 main (/usr/lib/llvm-19/bin/clang+0x1b706)
#75 0x00007f1c429b7083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#76 0x0000560ce114072e _start (/usr/lib/llvm-19/bin/clang+0xc72e)
clang++-19: error: clang frontend command failed with exit code 139 (use -v to see invocation)
Ubuntu clang version 19.1.4 (++20241111014147+a3f0f1d004a6-1~exp1~20241111134204.61)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/lib/llvm-19/bin
# Crash reproducer for Ubuntu clang version 19.1.4 (++20241111014147+a3f0f1d004a6-1~exp1~20241111134204.61)
# Driver args: "--driver-mode=g++" "-std=c++23" "-o" "test.o" "-c" "test.cpp"
# Original command:  "/usr/lib/llvm-19/bin/clang" "-cc1" "-triple" "x86_64-pc-linux-gnu" "-emit-obj" "-disable-free" "-clear-ast-before-backend" "-disable-llvm-verifier" "-discard-value-names" "-main-file-name" "test.cpp" "-mrelocation-model" "pic" "-pic-level" "2" "-pic-is-pie" "-mframe-pointer=all" "-fmath-errno" "-ffp-contract=on" "-fno-rounding-math" "-mconstructor-aliases" "-funwind-tables=2" "-target-cpu" "x86-64" "-tune-cpu" "generic" "-debugger-tuning=gdb" "-fdebug-compilation-dir=/tmp" "-fcoverage-compilation-dir=/tmp" "-resource-dir" "/usr/lib/llvm-19/lib/clang/19" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/14.2.0/../../../../include/c++/14.2.0" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/14.2.0/../../../../include/c++/14.2.0/x86_64-linux-gnu" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/14.2.0/../../../../include/c++/14.2.0/backward" "-internal-isystem" "/usr/lib/llvm-19/lib/clang/19/include" "-internal-isystem" "/usr/local/include" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/14.2.0/../../../../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++23" "-fdeprecated-macro" "-ferror-limit" "19" "-fgnuc-version=4.2.1" "-fno-implicit-modules" "-fskip-odr-check-in-gmf" "-fcxx-exceptions" "-fexceptions" "-fcolor-diagnostics" "-faddrsig" "-D__GCC_HAVE_DWARF2_CFI_ASM=1" "-o" "test.o" "-x" "c++" "test.cpp"
 "/usr/lib/llvm-19/bin/clang" "-cc1" "-triple" "x86_64-pc-linux-gnu" "-emit-obj" "-disable-free" "-clear-ast-before-backend" "-disable-llvm-verifier" "-discard-value-names" "-main-file-name" "test.cpp" "-mrelocation-model" "pic" "-pic-level" "2" "-pic-is-pie" "-mframe-pointer=all" "-fmath-errno" "-ffp-contract=on" "-fno-rounding-math" "-mconstructor-aliases" "-funwind-tables=2" "-target-cpu" "x86-64" "-tune-cpu" "generic" "-debugger-tuning=gdb" "-fdebug-compilation-dir=/tmp" "-fcoverage-compilation-dir=/tmp" "-std=c++23" "-fdeprecated-macro" "-ferror-limit" "19" "-fgnuc-version=4.2.1" "-fno-implicit-modules" "-fskip-odr-check-in-gmf" "-fcxx-exceptions" "-fexceptions" "-fcolor-diagnostics" "-faddrsig" "-D__GCC_HAVE_DWARF2_CFI_ASM=1" "-x" "c++" "test-5fa5ce.cpp"

Somehow can't reproduce in godbolt but got another (?) crash with assertion trunk: https://godbolt.org/z/abvenc4Md

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"conceptsC++20 conceptscrash-on-validlambdaC++11 lambda expressions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions