Skip to content

ICE on 'requires' for recursive function template #64462

@rollbear

Description

@rollbear

The following invalid code ICEs Clang++ 16.0.6. This is a reduction from a case I believe to be valid, and that was accepted by Clang++-15 (https://godbolt.org/z/axxY8TGWz)

auto c(auto, auto ... fs){return [](auto) requires(c(fs...)){};}
auto f = c([]{})(5);

with the backtrace:

$ clang++-16 -std=c++2b err.cpp
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: /usr/lib/llvm-16/bin/clang -cc1 -triple x86_64-pc-linux-gnu -emit-obj -mrelax-all -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name err.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 -mllvm -treat-scalable-fixed-error-as-warning -debugger-tuning=gdb -fcoverage-compilation-dir=/ -resource-dir /usr/lib/llvm-16/lib/clang/16 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/x86_64-linux-gnu/c++/12 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/backward -internal-isystem /usr/lib/llvm-16/lib/clang/16/include -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../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++2b -fdeprecated-macro -fdebug-compilation-dir=/ -ferror-limit 19 -fgnuc-version=4.2.1 -fno-implicit-modules -fcxx-exceptions -fexceptions -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/err-6f78a7.o -x c++ err.cpp
1.      err.cpp:2:19: current parser token ')'
 #0 0x00007f899cf08c16 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/usr/lib/llvm-16/bin/../lib/libLLVM-16.so.1+0xfc1c16)
 #1 0x00007f899cf06e60 llvm::sys::RunSignalHandlers() (/usr/lib/llvm-16/bin/../lib/libLLVM-16.so.1+0xfbfe60)
 #2 0x00007f899cf093eb (/usr/lib/llvm-16/bin/../lib/libLLVM-16.so.1+0xfc23eb)
 #3 0x00007f899b9ff4b0 (/lib/x86_64-linux-gnu/libc.so.6+0x3c4b0)
 #4 0x00007f89a500b3ee clang::Sema::CheckParameterPacksForExpansion(clang::SourceLocation, clang::SourceRange, llvm::ArrayRef<std::pair<llvm::PointerUnion<clang::TemplateTypeParmType const*, clang::NamedDecl*>, clang::SourceLocation>>, clang::MultiLevelTemplateArgumentList const&, bool&, bool&, std::optional<unsigned int>&) (/usr/lib/llvm-16/bin/../lib/libclang-cpp.so.16+0x1aa13ee)
 #5 0x00007f89a4fa2571 (/usr/lib/llvm-16/bin/../lib/libclang-cpp.so.16+0x1a38571)
 #6 0x00007f89a4fa85ab (/usr/lib/llvm-16/bin/../lib/libclang-cpp.so.16+0x1a3e5ab)
 #7 0x00007f89a4fa1f82 clang::Sema::SubstConstraintExpr(clang::Expr*, clang::MultiLevelTemplateArgumentList const&) (/usr/lib/llvm-16/bin/../lib/libclang-cpp.so.16+0x1a37f82)
 #8 0x00007f89a49cf387 (/usr/lib/llvm-16/bin/../lib/libclang-cpp.so.16+0x1465387)
 #9 0x00007f89a49ce279 (/usr/lib/llvm-16/bin/../lib/libclang-cpp.so.16+0x1464279)
#10 0x00007f89a49c94df (/usr/lib/llvm-16/bin/../lib/libclang-cpp.so.16+0x145f4df)
#11 0x00007f89a49c8e8c 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-16/bin/../lib/libclang-cpp.so.16+0x145ee8c)
#12 0x00007f89a49cb785 clang::Sema::CheckInstantiatedFunctionTemplateConstraints(clang::SourceLocation, clang::FunctionDecl*, llvm::ArrayRef<clang::TemplateArgument>, clang::ConstraintSatisfaction&) (/usr/lib/llvm-16/bin/../lib/libclang-cpp.so.16+0x1461785)
#13 0x00007f89a4f415df 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-16/bin/../lib/libclang-cpp.so.16+0x19d75df)
#14 0x00007f89a4f94ab7 (/usr/lib/llvm-16/bin/../lib/libclang-cpp.so.16+0x1a2aab7)
#15 0x00007f89a48966dd clang::Sema::runWithSufficientStackSpace(clang::SourceLocation, llvm::function_ref<void ()>) (/usr/lib/llvm-16/bin/../lib/libclang-cpp.so.16+0x132c6dd)
#16 0x00007f89a4f42a81 clang::Sema::DeduceTemplateArguments(clang::FunctionTemplateDecl*, clang::TemplateArgumentListInfo*, llvm::ArrayRef<clang::Expr*>, clang::FunctionDecl*&, clang::sema::TemplateDeductionInfo&, bool, llvm::function_ref<bool (llvm::ArrayRef<clang::QualType>)>) (/usr/lib/llvm-16/bin/../lib/libclang-cpp.so.16+0x19d8a81)
#17 0x00007f89a4e1f5f0 clang::Sema::AddMethodTemplateCandidate(clang::FunctionTemplateDecl*, clang::DeclAccessPair, clang::CXXRecordDecl*, clang::TemplateArgumentListInfo*, clang::QualType, clang::Expr::Classification, llvm::ArrayRef<clang::Expr*>, clang::OverloadCandidateSet&, bool, bool, clang::OverloadCandidateParamOrder) (/usr/lib/llvm-16/bin/../lib/libclang-cpp.so.16+0x18b55f0)
#18 0x00007f89a4e1ffc3 clang::Sema::AddMethodCandidate(clang::DeclAccessPair, clang::QualType, clang::Expr::Classification, llvm::ArrayRef<clang::Expr*>, clang::OverloadCandidateSet&, bool, clang::OverloadCandidateParamOrder) (/usr/lib/llvm-16/bin/../lib/libclang-cpp.so.16+0x18b5fc3)
#19 0x00007f89a4e36e67 clang::Sema::BuildCallToObjectOfClassType(clang::Scope*, clang::Expr*, clang::SourceLocation, llvm::MutableArrayRef<clang::Expr*>, clang::SourceLocation) (/usr/lib/llvm-16/bin/../lib/libclang-cpp.so.16+0x18cce67)
#20 0x00007f89a4b50681 clang::Sema::BuildCallExpr(clang::Scope*, clang::Expr*, clang::SourceLocation, llvm::MutableArrayRef<clang::Expr*>, clang::SourceLocation, clang::Expr*, bool, bool) (/usr/lib/llvm-16/bin/../lib/libclang-cpp.so.16+0x15e6681)
#21 0x00007f89a4b687fd clang::Sema::ActOnCallExpr(clang::Scope*, clang::Expr*, clang::SourceLocation, llvm::MutableArrayRef<clang::Expr*>, clang::SourceLocation, clang::Expr*) (/usr/lib/llvm-16/bin/../lib/libclang-cpp.so.16+0x15fe7fd)
#22 0x00007f89a417fa4c clang::Parser::ParsePostfixExpressionSuffix(clang::ActionResult<clang::Expr*, true>) (/usr/lib/llvm-16/bin/../lib/libclang-cpp.so.16+0xc15a4c)
#23 0x00007f89a4180965 clang::Parser::ParseCastExpression(clang::Parser::CastParseKind, bool, bool&, clang::Parser::TypeCastState, bool, bool*) (/usr/lib/llvm-16/bin/../lib/libclang-cpp.so.16+0xc16965)
#24 0x00007f89a417cbe1 clang::Parser::ParseAssignmentExpression(clang::Parser::TypeCastState) (/usr/lib/llvm-16/bin/../lib/libclang-cpp.so.16+0xc12be1)
#25 0x00007f89a414f26b clang::Parser::ParseDeclarationAfterDeclaratorAndAttributes(clang::Declarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::ForRangeInit*) (/usr/lib/llvm-16/bin/../lib/libclang-cpp.so.16+0xbe526b)
#26 0x00007f89a414c637 clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/usr/lib/llvm-16/bin/../lib/libclang-cpp.so.16+0xbe2637)
#27 0x00007f89a41fc557 clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/usr/lib/llvm-16/bin/../lib/libclang-cpp.so.16+0xc92557)
#28 0x00007f89a41fbf79 clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (/usr/lib/llvm-16/bin/../lib/libclang-cpp.so.16+0xc91f79)
#29 0x00007f89a41fb217 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/usr/lib/llvm-16/bin/../lib/libclang-cpp.so.16+0xc91217)
#30 0x00007f89a41f95be clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/usr/lib/llvm-16/bin/../lib/libclang-cpp.so.16+0xc8f5be)
#31 0x00007f89a413933e clang::ParseAST(clang::Sema&, bool, bool) (/usr/lib/llvm-16/bin/../lib/libclang-cpp.so.16+0xbcf33e)
#32 0x00007f89a5d503b5 clang::FrontendAction::Execute() (/usr/lib/llvm-16/bin/../lib/libclang-cpp.so.16+0x27e63b5)
#33 0x00007f89a5ccac94 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/usr/lib/llvm-16/bin/../lib/libclang-cpp.so.16+0x2760c94)
#34 0x00007f89a5dc9434 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/usr/lib/llvm-16/bin/../lib/libclang-cpp.so.16+0x285f434)
#35 0x000055dc45f3b116 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/usr/lib/llvm-16/bin/clang+0x15116)
#36 0x000055dc45f38280 (/usr/lib/llvm-16/bin/clang+0x12280)
#37 0x000055dc45f37f89 clang_main(int, char**) (/usr/lib/llvm-16/bin/clang+0x11f89)
#38 0x00007f899b9e6a90 (/lib/x86_64-linux-gnu/libc.so.6+0x23a90)
#39 0x00007f899b9e6b49 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x23b49)
#40 0x000055dc45f348b5 _start (/usr/lib/llvm-16/bin/clang+0xe8b5)
clang: error: unable to execute command: Segmentation fault (core dumped)
clang: error: clang frontend command failed due to signal (use -v to see invocation)
Ubuntu clang version 16.0.6 (++20230710042020+7cbf1a259152-1~exp1~20230710162037.55)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
clang: note: diagnostic msg: 
********************

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

********************

/tmp/err-c1b700.cpp:

# 1 "err.cpp"
# 1 "<built-in>" 1
# 1 "<built-in>" 3
# 451 "<built-in>" 3
# 1 "<command line>" 1
# 1 "<built-in>" 2
# 1 "err.cpp" 2
auto c(auto, auto ... fs){return [](auto) requires(c(fs...)){};}
auto f = c([]{})(5);

/tmp/err-c1b700.sh:

# Crash reproducer for Ubuntu clang version 16.0.6 (++20230710042020+7cbf1a259152-1~exp1~20230710162037.55)
# Driver args: "--driver-mode=g++" "-std=c++2b" "err.cpp"
# Original command:  "/usr/lib/llvm-16/bin/clang" "-cc1" "-triple" "x86_64-pc-linux-gnu" "-emit-obj" "-mrelax-all" "-disable-free" "-clear-ast-before-backend" "-disable-llvm-verifier" "-discard-value-names" "-main-file-name" "err.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" "-mllvm" "-treat-scalable-fixed-error-as-warning" "-debugger-tuning=gdb" "-fcoverage-compilation-dir=/" "-resource-dir" "/usr/lib/llvm-16/lib/clang/16" "-internal-isystem" "/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12" "-internal-isystem" "/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/x86_64-linux-gnu/c++/12" "-internal-isystem" "/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/backward" "-internal-isystem" "/usr/lib/llvm-16/lib/clang/16/include" "-internal-isystem" "/usr/local/include" "-internal-isystem" "/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../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++2b" "-fdeprecated-macro" "-fdebug-compilation-dir=/" "-ferror-limit" "19" "-fgnuc-version=4.2.1" "-fno-implicit-modules" "-fcxx-exceptions" "-fexceptions" "-faddrsig" "-D__GCC_HAVE_DWARF2_CFI_ASM=1" "-o" "/tmp/err-6f78a7.o" "-x" "c++" "err.cpp"
 "/usr/lib/llvm-16/bin/clang" "-cc1" "-triple" "x86_64-pc-linux-gnu" "-emit-obj" "-mrelax-all" "-disable-free" "-clear-ast-before-backend" "-disable-llvm-verifier" "-discard-value-names" "-main-file-name" "err.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" "-mllvm" "-treat-scalable-fixed-error-as-warning" "-debugger-tuning=gdb" "-fcoverage-compilation-dir=/" "-std=c++2b" "-fdeprecated-macro" "-fdebug-compilation-dir=/" "-ferror-limit" "19" "-fgnuc-version=4.2.1" "-fno-implicit-modules" "-fcxx-exceptions" "-fexceptions" "-faddrsig" "-D__GCC_HAVE_DWARF2_CFI_ASM=1" "-x" "c++" "err-c1b700.cpp"

Metadata

Metadata

Assignees

Labels

c++20clang:frontendLanguage frontend issues, e.g. anything involving "Sema"conceptsC++20 conceptsconfirmedVerified by a second partycrashPrefer [crash-on-valid] or [crash-on-invalid]regression

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions