llvm / llvm/llvm-project

[Clang] Assertion failure in `Sema::DeclareAggregateDeductionGuideFromInitList` when using CTAD with alias templates

Open
#176,389 1 comment 0 reactions 0 assignees View on GitHub
clang:frontend crash generated by fuzzer regression:19
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

***Generated by fuzzer.***
Clang trunk crashed and goes back to 19.1.
Compiler Explorer: https://godbolt.org/z/6oaj86rnq

## Program
```cpp
import M; template < typename > struct A{int u } template < class T > using B = A< T >;
b_type(B{})
```

## Stack Dump
```bash
:1:8: fatal error: module 'M' not found
1 | import M; template < typename > struct A{int u } template < class T > using B = A< T >;
| ~~~~~~~^
clang++: /root/llvm-project/llvm/include/llvm/Support/Casting.h:572: decltype(auto) llvm::cast(From*) [with To = clang::CXXRecordDecl; From = clang::NamedDecl]: Assertion `isa(Val) && "cast() argument of incompatible type!"' 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: /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++23
1. :2:11: current parser token ')'
#0 0x000000000430a6b8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x430a6b8)
#1 0x0000000004307b14 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4307b14)
#2 0x0000000004249de8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#3 0x00007f6ee2e42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#4 0x00007f6ee2e969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
#5 0x00007f6ee2e42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
#6 0x00007f6ee2e287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
#7 0x00007f6ee2e2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
#8 0x00007f6ee2e39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#9 0x00000000075659ff clang::Sema::DeclareAggregateDeductionGuideFromInitList(clang::TemplateDecl*, llvm::MutableArrayRef, clang::SourceLocation) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x75659ff)
#10 0x0000000007133141 clang::Sema::DeduceTemplateSpecializationFromInitializer(clang::TypeSourceInfo*, clang::InitializedEntity const&, clang::InitializationKind const&, llvm::MutableArrayRef)::'lambda0'(bool)::operator()(bool) const::'lambda'(clang::InitListExpr*)::operator()(clang::InitListExpr*) const SemaInit.cpp:0:0
#11 0x0000000007133682 clang::Sema::DeduceTemplateSpecializationFromInitializer(clang::TypeSourceInfo*, clang::InitializedEntity const&, clang::InitializationKind const&, llvm::MutableArrayRef)::'lambda0'(bool)::operator()(bool) const SemaInit.cpp:0:0
#12 0x0000000007133d75 clang::Sema::DeduceTemplateSpecializationFromInitializer(clang::TypeSourceInfo*, clang::InitializedEntity const&, clang::InitializationKind const&, llvm::MutableArrayRef) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7133d75)
#13 0x000000000708d60d clang::Sema::BuildCXXTypeConstructExpr(clang::TypeSourceInfo*, clang::SourceLocation, llvm::MutableArrayRef, clang::SourceLocation, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x708d60d)
#14 0x000000000708db39 clang::Sema::ActOnCXXTypeConstructExpr(clang::OpaquePtr, clang::SourceLocation, llvm::MutableArrayRef, clang::SourceLocation, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x708db39)
#15 0x0000000006afb2e6 clang::Parser::ParseCXXTypeConstructExpression(clang::DeclSpec const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6afb2e6)
#16 0x0000000006adf670 clang::Parser::ParseCastExpression(clang::CastParseKind, bool, bool&, clang::TypoCorrectionTypeBehavior, bool, bool*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6adf670)
#17 0x0000000006ae0217 clang::Parser::ParseCastExpression(clang::CastParseKind, bool, clang::TypoCorrectionTypeBehavior, bool, bool*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6ae0217)
#18 0x0000000006ae02a9 clang::Parser::ParseAssignmentExpression(clang::TypoCorrectionTypeBehavior) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6ae02a9)
#19 0x0000000006ae060e clang::Parser::ParseExpressionList(llvm::SmallVectorImpl&, llvm::function_ref, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6ae060e)
#20 0x0000000006a998da clang::Parser::ParseDeclarationAfterDeclaratorAndAttributes(clang::Declarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6a998da)
#21 0x0000000006aa702a 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+++0x6aa702a)
#22 0x0000000006a6472b clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6a6472b)
#23 0x0000000006a64f1f clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6a64f1f)
#24 0x0000000006a6cd4a clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6a6cd4a)
#25 0x0000000006a6dce5 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6a6dce5)
#26 0x0000000006a4ed6a clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6a4ed6a)
#27 0x0000000004c722a8 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4c722a8)
#28 0x0000000004f6bc55 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4f6bc55)
#29 0x0000000004eeb8de clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4eeb8de)
#30 0x000000000506698d clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x506698d)
#31 0x0000000000ddcf9e cc1_main(llvm::ArrayRef, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xddcf9e)
#32 0x0000000000dd396a ExecuteCC1Tool(llvm::SmallVectorImpl&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr) driver.cpp:0:0
#33 0x0000000000dd3aed int llvm::function_ref&)>::callback_fn&)>(long, llvm::SmallVectorImpl&) driver.cpp:0:0
#34 0x0000000004ce55a9 void llvm::function_ref::callback_fn>, std::__cxx11::basic_string, std::allocator>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#35 0x000000000424a284 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x424a284)
#36 0x0000000004ce5bbf clang::driver::CC1Command::Execute(llvm::ArrayRef>, std::__cxx11::basic_string, std::allocator>*, bool*) const (.part.0) Job.cpp:0:0
#37 0x0000000004ca6592 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4ca6592)
#38 0x0000000004ca753e clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4ca753e)
#39 0x0000000004cae985 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4cae985)
#40 0x0000000000dd9311 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdd9311)
#41 0x0000000000c969c4 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xc969c4)
#42 0x00007f6ee2e29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#43 0x00007f6ee2e29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#44 0x0000000000dd3405 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdd3405)
clang++: error: clang frontend command failed with exit code 134 (use -v to see invocation)
Compiler returned: 134
```

Contributor guide

Open the contributing guide

Research direction

Reproduce the assertion with the C++ program and compiler invocation from the issue, using the linked Compiler Explorer example as a reference. Start in clang::Sema::DeclareAggregateDeductionGuideFromInitList, then trace the call through DeduceTemplateSpecializationFromInitializer. Done means the alias-template CTAD case no longer triggers the assertion and has regression coverage.

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
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.