llvm / llvm/llvm-project

[clang] Assertion `getCommonPtr()->InstantiatedFromMember.getPointer() && "Only member templates can be member template specializations"' failed.

Open
#210,221 3 comments 0 reactions 0 assignees View on GitHub
clang:frontend crash-on-invalid generated by fuzzer regression:23
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Reproducer:
https://godbolt.org/z/E7ef66Yjc
```cpp
template struct S {};
template <> template int S::foo;
template <> template int S::foo;
template <> template constexpr int S::foo;
```

Backtrace:
```console
clang++: /root/llvm-project/llvm/tools/clang/include/clang/AST/DeclTemplate.h:858: void clang::RedeclarableTemplateDecl::setMemberSpecialization(): Assertion `getCommonPtr()->InstantiatedFromMember.getPointer() && "Only member templates can be member template specializations"' failed.
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
1. :4:61: current parser token ';'
#0 0x00000000043f3668 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x43f3668)
#1 0x00000000043f0524 llvm::sys::RunSignalHandlers() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x43f0524)
#2 0x00000000043f0b4c llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x43f0b4c)
#3 0x000000000432fb88 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#4 0x00007936aa645330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
#5 0x00007936aa69eb2c pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x9eb2c)
#6 0x00007936aa64527e raise (/lib/x86_64-linux-gnu/libc.so.6+0x4527e)
#7 0x00007936aa6288ff abort (/lib/x86_64-linux-gnu/libc.so.6+0x288ff)
#8 0x00007936aa62881b (/lib/x86_64-linux-gnu/libc.so.6+0x2881b)
#9 0x00007936aa63b517 (/lib/x86_64-linux-gnu/libc.so.6+0x3b517)
#10 0x00000000070f5ecb clang::Sema::ActOnVariableDeclarator(clang::Scope*, clang::Declarator&, clang::DeclContext*, clang::TypeSourceInfo*, clang::LookupResult&, llvm::MutableArrayRef, bool&, llvm::ArrayRef) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x70f5ecb)
#11 0x0000000007110777 clang::Sema::HandleDeclarator(clang::Scope*, clang::Declarator&, llvm::MutableArrayRef) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7110777)
#12 0x0000000007718e6e clang::Sema::ActOnTemplateDeclarator(clang::Scope*, llvm::MutableArrayRef, clang::Declarator&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7718e6e)
#13 0x0000000006d37dde clang::Parser::ParseDeclarationAfterDeclaratorAndAttributes(clang::Declarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d37dde)
#14 0x0000000006d587f9 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+++0x6d587f9)
#15 0x0000000006e1d180 clang::Parser::ParseDeclarationAfterTemplate(clang::DeclaratorContext, clang::Parser::ParsedTemplateInfo&, clang::ParsingDeclRAIIObject&, clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e1d180)
#16 0x0000000006e297f3 clang::Parser::ParseTemplateDeclarationOrSpecialization(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier) (.part.0) ParseTemplate.cpp:0:0
#17 0x0000000006e29bea clang::Parser::ParseDeclarationStartingWithTemplate(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e29bea)
#18 0x0000000006d5a2b0 clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::ParsedAttributes&, clang::SourceLocation*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d5a2b0)
#19 0x0000000006d10df6 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d10df6)
#20 0x0000000006d11ce5 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d11ce5)
#21 0x0000000006ceebfa clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6ceebfa)
#22 0x0000000004ef1628 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4ef1628)
#23 0x000000000521ccc8 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x521ccc8)
#24 0x00000000051aa16d clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x51aa16d)
#25 0x00000000052f53fd clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x52f53fd)
#26 0x0000000000da6c9c cc1_main(llvm::ArrayRef, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xda6c9c)
#27 0x0000000000d9d8aa ExecuteCC1Tool(llvm::SmallVectorImpl&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr) driver.cpp:0:0
#28 0x0000000000d9da2d int llvm::function_ref&)>::callback_fn&)>(long, llvm::SmallVectorImpl&) driver.cpp:0:0
#29 0x0000000004f688f9 void llvm::function_ref::callback_fn>, std::__cxx11::basic_string, std::allocator>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#30 0x000000000432ffc4 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x432ffc4)
#31 0x0000000004f69465 clang::driver::CC1Command::Execute(llvm::ArrayRef>, std::__cxx11::basic_string, std::allocator>*, bool*) const (.part.0) Job.cpp:0:0
#32 0x0000000004f21e32 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4f21e32)
#33 0x0000000004f26667 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4f26667)
#34 0x0000000004f30bc5 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4f30bc5)
#35 0x0000000000da318a clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xda318a)
#36 0x0000000000cbef4a main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xcbef4a)
#37 0x00007936aa62a1ca (/lib/x86_64-linux-gnu/libc.so.6+0x2a1ca)
#38 0x00007936aa62a28b __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a28b)
#39 0x0000000000d9d255 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xd9d255)
clang++: error: clang frontend command failed due to signal (use -v to see invocation)
Compiler returned: 134
```

Contributor guide

Open the contributing guide

Research direction

Run the linked Godbolt reproducer first, then inspect the assertion in llvm/tools/clang/include/clang/AST/DeclTemplate.h and the reported clang::Sema::ActOnVariableDeclarator entry point. Determine how the repeated template declarations reach this assertion; done means the reproducer no longer aborts while preserving the intended diagnostic or compilation behavior.

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.