[libcxx-commits] [clang] [libcxx] [clang] Preserve Qualifiers and type sugar in TemplateNames (PR #93433)

kadir çetinkaya via libcxx-commits libcxx-commits at lists.llvm.org
Fri Jun 7 04:45:16 PDT 2024


kadircet wrote:

so after this patch, clang seems to be crashing on:
```cpp
template <typename T, typename Y> struct map {};
template <typename T> class foo {};

template <template <typename...> class MapType, typename Value>
Value bar(MapType<int, Value> map);

template <template <typename...> class MapType, typename Value>
Value bar(MapType<int, foo<Value>> map);

void aux() {
  map<int, foo<int>> input;
  bar(input);
}
```

stack trace:
```
$ ./bin/clang -fsyntax-only -xc++ -std=c++20 -Wno-everything foo.cc
clang: /usr/local/google/home/kadircet/repos/llvm/clang/lib/Sema/SemaTemplateDeduction.cpp:596: TemplateDeductionResult DeduceTemplateArguments(Sema &, TemplateParameterList *, TemplateName, TemplateName, TemplateDeductionInfo &, ArrayRef<TemplateArgument>, SmallVectorImpl<DeducedTemplateArgument> &): Assertion `DefaultArguments.size() <= As->size()' failed.
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: ./bin/clang -fsyntax-only -xc++ -std=c++20 -Wno-everything myreduce.cc
1.      myreduce.cc:12:12: current parser token ')'
2.      myreduce.cc:10:12: parsing function body 'aux'
3.      myreduce.cc:10:12: in compound statement ('{}')
 #0 0x0000561942c22558 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /usr/local/google/home/kadircet/repos/llvm/llvm/lib/Support/Unix/Signals.inc:723:13
 #1 0x0000561942c2011e llvm::sys::RunSignalHandlers() /usr/local/google/home/kadircet/repos/llvm/llvm/lib/Support/Signals.cpp:106:18
 #2 0x0000561942b8c686 HandleCrash /usr/local/google/home/kadircet/repos/llvm/llvm/lib/Support/CrashRecoveryContext.cpp:73:5
 #3 0x0000561942b8c686 CrashRecoverySignalHandler(int) /usr/local/google/home/kadircet/repos/llvm/llvm/lib/Support/CrashRecoveryContext.cpp:390:51
 #4 0x00007fa5f6e5a510 (/lib/x86_64-linux-gnu/libc.so.6+0x3c510)
 #5 0x00007fa5f6ea816c __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
 #6 0x00007fa5f6e5a472 raise ./signal/../sysdeps/posix/raise.c:27:6
 #7 0x00007fa5f6e444b2 abort ./stdlib/abort.c:81:7
 #8 0x00007fa5f6e443d5 _nl_load_domain ./intl/loadmsgcat.c:1177:9
 #9 0x00007fa5f6e533a2 (/lib/x86_64-linux-gnu/libc.so.6+0x353a2)
#10 0x0000561945cbacbc set_size /usr/local/google/home/kadircet/repos/llvm/llvm/include/llvm/ADT/SmallVector.h:102:5
#11 0x0000561945cbacbc resizeImpl<false> /usr/local/google/home/kadircet/repos/llvm/llvm/include/llvm/ADT/SmallVector.h:647:11
#12 0x0000561945cbacbc resize /usr/local/google/home/kadircet/repos/llvm/llvm/include/llvm/ADT/SmallVector.h:651:30
#13 0x0000561945cbacbc SmallVector /usr/local/google/home/kadircet/repos/llvm/llvm/include/llvm/ADT/SmallVector.h:1220:11
#14 0x0000561945cbacbc DeduceTemplateArguments(clang::Sema&, clang::TemplateParameterList*, clang::TemplateName, clang::TemplateName, clang::sema::TemplateDeductionInfo&, llvm::ArrayRef<clang::TemplateArgument>, llvm::SmallVectorImpl<clang::DeducedTemplateArgument>&) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Sema/SemaTemplateDeduction.cpp:597:37
#15 0x0000561945cbde14 DeduceTemplateSpecArguments(clang::Sema&, clang::TemplateParameterList*, clang::QualType, clang::QualType, clang::sema::TemplateDeductionInfo&, llvm::SmallVectorImpl<clang::DeducedTemplateArgument>&) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Sema/SemaTemplateDeduction.cpp:717:13
#16 0x0000561945caf095 DeduceTemplateArgumentsByTypeMatch(clang::Sema&, clang::TemplateParameterList*, clang::QualType, clang::QualType, clang::sema::TemplateDeductionInfo&, llvm::SmallVectorImpl<clang::DeducedTemplateArgument>&, unsigned int, bool, bool) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Sema/SemaTemplateDeduction.cpp:0:16
#17 0x0000561945cbd8e2 DeduceTemplateArguments(clang::Sema&, clang::TemplateParameterList*, clang::QualType const*, unsigned int, clang::QualType const*, unsigned int, clang::sema::TemplateDeductionInfo&, llvm::SmallVectorImpl<clang::DeducedTemplateArgument>&, unsigned int, bool) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Sema/SemaTemplateDeduction.cpp:1223:44
#18 0x0000561945cb5910 isAtLeastAsSpecializedAs(clang::Sema&, clang::SourceLocation, clang::FunctionTemplateDecl const*, clang::FunctionTemplateDecl const*, clang::TemplatePartialOrderingContext, bool, llvm::SmallVector<clang::QualType, 6u> const&, llvm::SmallVector<clang::QualType, 6u> const&) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Sema/SemaTemplateDeduction.cpp:0:0
#19 0x0000561945cb45df clang::Sema::getMoreSpecializedTemplate(clang::FunctionTemplateDecl*, clang::FunctionTemplateDecl*, clang::SourceLocation, clang::TemplatePartialOrderingContext, unsigned int, clang::QualType, clang::QualType, bool) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Sema/SemaTemplateDeduction.cpp:0:18
#20 0x0000561945aef302 clang::isBetterOverloadCandidate(clang::Sema&, clang::OverloadCandidate const&, clang::OverloadCandidate const&, clang::SourceLocation, clang::OverloadCandidateSet::CandidateSetKind) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Sema/SemaOverload.cpp:0:50
#21 0x0000561945ae0836 clang::OverloadCandidateSet::BestViableFunction(clang::Sema&, clang::SourceLocation, clang::OverloadCandidate*&) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Sema/SemaOverload.cpp:10883:11
#22 0x0000561945af97a9 clang::Sema::BuildOverloadedCallExpr(clang::Scope*, clang::Expr*, clang::UnresolvedLookupExpr*, clang::SourceLocation, llvm::MutableArrayRef<clang::Expr*>, clang::SourceLocation, clang::Expr*, bool, bool) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Sema/SemaOverload.cpp:14194:20
#23 0x00005619456f14c3 clang::Sema::BuildCallExpr(clang::Scope*, clang::Expr*, clang::SourceLocation, llvm::MutableArrayRef<clang::Expr*>, clang::SourceLocation, clang::Expr*, bool, bool) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Sema/SemaExpr.cpp:6555:16
#24 0x000056194570811a clang::Sema::ActOnCallExpr(clang::Scope*, clang::Expr*, clang::SourceLocation, llvm::MutableArrayRef<clang::Expr*>, clang::SourceLocation, clang::Expr*) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Sema/SemaExpr.cpp:6446:7
#25 0x00005619451c0358 clang::Parser::ParsePostfixExpressionSuffix(clang::ActionResult<clang::Expr*, true>) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Parse/ParseExpr.cpp:2206:23
#26 0x00005619451c4bbd clang::Parser::ParseCastExpression(clang::Parser::CastParseKind, bool, bool&, clang::Parser::TypeCastState, bool, bool*) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Parse/ParseExpr.cpp:1908:9
#27 0x00005619451bd35c ParseCastExpression /usr/local/google/home/kadircet/repos/llvm/clang/lib/Parse/ParseExpr.cpp:0:20
#28 0x00005619451bd35c clang::Parser::ParseAssignmentExpression(clang::Parser::TypeCastState) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Parse/ParseExpr.cpp:182:20
#29 0x00005619451bd259 clang::Parser::ParseExpression(clang::Parser::TypeCastState) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Parse/ParseExpr.cpp:134:10
#30 0x0000561945253ce1 isInvalid /usr/local/google/home/kadircet/repos/llvm/clang/include/clang/Sema/Ownership.h:199:41
#31 0x0000561945253ce1 clang::Parser::ParseExprStatement(clang::Parser::ParsedStmtContext) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Parse/ParseStmt.cpp:552:12
#32 0x0000561945251acc clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::ParsedAttributes&, clang::ParsedAttributes&) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Parse/ParseStmt.cpp:0:14
#33 0x00005619452513b2 clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Parse/ParseStmt.cpp:121:20
#34 0x000056194525b8b1 clang::Parser::ParseCompoundStatementBody(bool) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Parse/ParseStmt.cpp:1248:11
#35 0x000056194525c952 clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Parse/ParseStmt.cpp:2526:21
#36 0x000056194519c469 clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Parse/Parser.cpp:0:0
#37 0x0000561945211c9d clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::Parser::ParsedTemplateInfo&, clang::SourceLocation*, clang::Parser::ForRangeInit*) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Parse/ParseDecl.cpp:2394:18
#38 0x000056194519b089 clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Parse/Parser.cpp:0:10
#39 0x000056194519a8e2 clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Parse/Parser.cpp:1271:12
#40 0x0000561945199709 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Parse/Parser.cpp:0:14
#41 0x0000561945197736 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Parse/Parser.cpp:763:10
#42 0x0000561945192d5e clang::ParseAST(clang::Sema&, bool, bool) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Parse/ParseAST.cpp:162:5
#43 0x000056194389a37f clang::FrontendAction::Execute() /usr/local/google/home/kadircet/repos/llvm/clang/lib/Frontend/FrontendAction.cpp:1082:10
#44 0x000056194380728d getPtr /usr/local/google/home/kadircet/repos/llvm/llvm/include/llvm/Support/Error.h:276:42
#45 0x000056194380728d operator bool /usr/local/google/home/kadircet/repos/llvm/llvm/include/llvm/Support/Error.h:239:16
#46 0x000056194380728d clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Frontend/CompilerInstance.cpp:1061:23
#47 0x000056194398013e clang::ExecuteCompilerInvocation(clang::CompilerInstance*) /usr/local/google/home/kadircet/repos/llvm/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:280:25
#48 0x00005619404c7baf cc1_main(llvm::ArrayRef<char const*>, char const*, void*) /usr/local/google/home/kadircet/repos/llvm/clang/tools/driver/cc1_main.cpp:232:15
#49 0x00005619404c448d ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) /usr/local/google/home/kadircet/repos/llvm/clang/tools/driver/driver.cpp:215:12
#50 0x0000561943645c99 operator() /usr/local/google/home/kadircet/repos/llvm/clang/lib/Driver/Job.cpp:440:30
#51 0x0000561943645c99 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::$_0>(long) /usr/local/google/home/kadircet/repos/llvm/llvm/include/llvm/ADT/STLFunctionalExtras.h:45:12
#52 0x0000561942b8c3c6 operator() /usr/local/google/home/kadircet/repos/llvm/llvm/include/llvm/ADT/STLFunctionalExtras.h:0:12
#53 0x0000561942b8c3c6 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) /usr/local/google/home/kadircet/repos/llvm/llvm/lib/Support/CrashRecoveryContext.cpp:426:3
#54 0x0000561943645392 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/local/google/home/kadircet/repos/llvm/clang/lib/Driver/Job.cpp:440:7
#55 0x00005619435fd4c7 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const /usr/local/google/home/kadircet/repos/llvm/clang/lib/Driver/Compilation.cpp:199:15
#56 0x00005619435fda07 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const /usr/local/google/home/kadircet/repos/llvm/clang/lib/Driver/Compilation.cpp:253:13
#57 0x000056194361e719 empty /usr/local/google/home/kadircet/repos/llvm/llvm/include/llvm/ADT/SmallVector.h:94:46
#58 0x000056194361e719 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Driver/Driver.cpp:1942:23
#59 0x00005619404c398d clang_main(int, char**, llvm::ToolContext const&) /usr/local/google/home/kadircet/repos/llvm/clang/tools/driver/driver.cpp:391:21
#60 0x00005619404d44f7 main /usr/local/google/home/kadircet/repos/llvm/build/tools/clang/tools/driver/clang-driver.cpp:17:10
#61 0x00007fa5f6e456ca __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3
#62 0x00007fa5f6e45785 call_init ./csu/../csu/libc-start.c:128:20
#63 0x00007fa5f6e45785 __libc_start_main ./csu/../csu/libc-start.c:347:5
#64 0x00005619404c1de1 _start (./bin/clang+0x546ede1)
```

@yozhu this is the same assertion you mentioned in https://github.com/llvm/llvm-project/pull/94659, but doesn't really involve default template args, so I am not sure if this is the same kind of reproducer.

https://github.com/llvm/llvm-project/pull/93433


More information about the libcxx-commits mailing list