[clang] crash on invalid use of an alias template without template arguments
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
Reproducer:
https://godbolt.org/z/hzhTxnTGs
```cpp
template struct Foo { T t; };
template using AFoo = Foo;
AFoo s = { 42 };
```
Backtrace:
```console
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and dumped files.
Stack dump:
0. Program arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/clang++ -g -o /app/output.s -mllvm --x86-asm-syntax=intel -fno-verbose-asm -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics -std=c++20
1. :3:16: current parser token ';'
#0 0x0000000004381c58 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4381c58)
#1 0x000000000437eb74 llvm::sys::RunSignalHandlers() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x437eb74)
#2 0x000000000437f194 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x437f194)
#3 0x00000000042bd248 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#4 0x000070bf2b445330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
#5 0x0000000007e95280 clang::Decl::isTemplateDecl() const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7e95280)
#6 0x0000000007570e78 (anonymous namespace)::ClassifyOverloadCandidate(clang::Sema&, clang::NamedDecl const*, clang::FunctionDecl const*, clang::OverloadCandidateRewriteKind, std::__cxx11::basic_string, std::allocator>&) SemaOverload.cpp:0:0
#7 0x000000000758e2a6 DiagnoseBadConversion(clang::Sema&, clang::OverloadCandidate*, unsigned int, bool) SemaOverload.cpp:0:0
#8 0x00000000075b84d0 clang::OverloadCandidateSet::NoteCandidates(clang::Sema&, llvm::ArrayRef, llvm::ArrayRef, llvm::StringRef, clang::SourceLocation) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x75b84d0)
#9 0x00000000075b8ef1 clang::OverloadCandidateSet::NoteCandidates(std::pair, clang::Sema&, clang::OverloadCandidateDisplayKind, llvm::ArrayRef, llvm::StringRef, clang::SourceLocation, llvm::function_ref) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x75b8ef1)
#10 0x000000000736fe97 clang::Sema::DeduceTemplateSpecializationFromInitializer(clang::TypeSourceInfo*, clang::InitializedEntity const&, clang::InitializationKind const&, llvm::MutableArrayRef) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x736fe97)
#11 0x000000000703f6ed clang::Sema::deduceVarTypeFromInitializer(clang::VarDecl*, clang::DeclarationName, clang::QualType, clang::TypeSourceInfo*, clang::SourceRange, bool, clang::Expr*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x703f6ed)
#12 0x000000000704176d clang::Sema::DeduceVariableDeclarationType(clang::VarDecl*, bool, clang::Expr*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x704176d)
#13 0x00000000070758e8 clang::Sema::AddInitializerToDecl(clang::Decl*, clang::Expr*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x70758e8)
#14 0x0000000006cb83b1 clang::Parser::ParseDeclarationAfterDeclaratorAndAttributes(clang::Declarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6cb83b1)
#15 0x0000000006cd7d12 clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::Parser::ParsedTemplateInfo&, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6cd7d12)
#16 0x0000000006c8363b clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6c8363b)
#17 0x0000000006c83e3f clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6c83e3f)
#18 0x0000000006c90661 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6c90661)
#19 0x0000000006c91575 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6c91575)
#20 0x0000000006c6f18a clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6c6f18a)
#21 0x0000000004e70138 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4e70138)
#22 0x000000000519b238 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x519b238)
#23 0x000000000512700d clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x512700d)
#24 0x000000000529c61d clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x529c61d)
#25 0x0000000000dbc12c cc1_main(llvm::ArrayRef, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdbc12c)
#26 0x0000000000db2d3a ExecuteCC1Tool(llvm::SmallVectorImpl&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr) driver.cpp:0:0
#27 0x0000000000db2ebd int llvm::function_ref&)>::callback_fn&)>(long, llvm::SmallVectorImpl&) driver.cpp:0:0
#28 0x0000000004ee2cd9 void llvm::function_ref::callback_fn>, std::__cxx11::basic_string, std::allocator>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#29 0x00000000042bd684 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x42bd684)
#30 0x0000000004ee3805 clang::driver::CC1Command::Execute(llvm::ArrayRef>, std::__cxx11::basic_string, std::allocator>*, bool*) const (.part.0) Job.cpp:0:0
#31 0x0000000004e9ed92 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4e9ed92)
#32 0x0000000004e9fdae clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4e9fdae)
#33 0x0000000004eabf15 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4eabf15)
#34 0x0000000000db861a clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdb861a)
#35 0x0000000000ccd8fa main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xccd8fa)
#36 0x000070bf2b42a1ca (/lib/x86_64-linux-gnu/libc.so.6+0x2a1ca)
#37 0x000070bf2b42a28b __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a28b)
#38 0x0000000000db26e5 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdb26e5)
clang++: error: clang frontend command failed due to signal (use -v to see invocation)
Compiler returned: 139
```
Contributor guide
Research direction
Reproduce the crash with the C++ example and inspect SemaOverload.cpp, especially ClassifyOverloadCandidate and the Sema::DeduceTemplateSpecializationFromInitializer path shown in the backtrace. Trace the invalid alias-template case, add regression coverage where appropriate, and verify that Clang reports a diagnostic instead of crashing.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100