llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[clang] Assertion `isa<CXXRecordDecl>(D->getDeclContext()) && "not a member specialization"' failed.

Open k-arrows opened this issue 5 months ago • 3 comments

Reproducer: https://godbolt.org/z/vb5zPof51

template <typename T> struct A {
  void B { int y = 0; };
  template <typename U> int x = 0;
}

template <typename U>
struct A<long>::B<U &> {
};
template <typename U> int A<int>::x = 3;
template <> template <typename U> int A<int>::x<U &> = 4;

static_assert(A<long>::x<int &> == 5);

Backtrace:

clang++: /root/llvm-project/llvm/tools/clang/lib/Sema/SemaLookup.cpp:1809: bool hasAcceptableMemberSpecialization(clang::Sema&, const clang::NamedDecl*, llvm::SmallVectorImpl<clang::Module*>*, clang::Sema::AcceptableKind): Assertion `isa<CXXRecordDecl>(D->getDeclContext()) && "not a member specialization"' 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 -std=c++20 <source>
1.	<source>:12:33: current parser token '=='
 #0 0x000000000434c4d8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x434c4d8)
 #1 0x0000000004349414 llvm::sys::RunSignalHandlers() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4349414)
 #2 0x0000000004349a34 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4349a34)
 #3 0x0000000004286f78 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #4 0x0000730464645330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
 #5 0x000073046469eb2c pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x9eb2c)
 #6 0x000073046464527e raise (/lib/x86_64-linux-gnu/libc.so.6+0x4527e)
 #7 0x00007304646288ff abort (/lib/x86_64-linux-gnu/libc.so.6+0x288ff)
 #8 0x000073046462881b (/lib/x86_64-linux-gnu/libc.so.6+0x2881b)
 #9 0x000073046463b517 (/lib/x86_64-linux-gnu/libc.so.6+0x3b517)
#10 0x000000000734e4e4 (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x734e4e4)
#11 0x000000000764a054 (anonymous namespace)::ExplicitSpecializationVisibilityChecker::check(clang::NamedDecl*) (.constprop.0) SemaTemplate.cpp:0:0
#12 0x000000000764a33b clang::Sema::checkSpecializationReachability(clang::SourceLocation, clang::NamedDecl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x764a33b)
#13 0x000000000767249a clang::Sema::CheckVarTemplateId(clang::VarTemplateDecl*, clang::SourceLocation, clang::SourceLocation, clang::TemplateArgumentListInfo const&, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x767249a)
#14 0x0000000007672e44 clang::Sema::CheckVarTemplateId(clang::CXXScopeSpec const&, clang::DeclarationNameInfo const&, clang::VarTemplateDecl*, clang::NamedDecl*, clang::SourceLocation, clang::TemplateArgumentListInfo const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7672e44)
#15 0x00000000076730a7 clang::Sema::BuildTemplateIdExpr(clang::CXXScopeSpec const&, clang::SourceLocation, clang::LookupResult&, bool, clang::TemplateArgumentListInfo const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x76730a7)
#16 0x00000000071a0878 clang::Sema::ActOnIdExpression(clang::Scope*, clang::CXXScopeSpec&, clang::SourceLocation, clang::UnqualifiedId&, bool, bool, clang::CorrectionCandidateCallback*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x71a0878)
#17 0x0000000006cd3501 clang::Parser::tryParseCXXIdExpression(clang::CXXScopeSpec&, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6cd3501)
#18 0x0000000006cd379e clang::Parser::ParseCXXIdExpression(bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6cd379e)
#19 0x0000000006cb7934 clang::Parser::ParseCastExpression(clang::CastParseKind, bool, bool&, clang::TypoCorrectionTypeBehavior, bool, bool*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6cb7934)
#20 0x0000000006cb7210 clang::Parser::ParseCastExpression(clang::CastParseKind, bool, bool&, clang::TypoCorrectionTypeBehavior, bool, bool*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6cb7210)
#21 0x0000000006cc410e clang::Parser::ParseConstantExpressionInExprEvalContext(clang::TypoCorrectionTypeBehavior) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6cc410e)
#22 0x0000000006c9b8a6 clang::Parser::ParseStaticAssertDeclaration(clang::SourceLocation&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6c9b8a6)
#23 0x0000000006c8a146 clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::ParsedAttributes&, clang::SourceLocation*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6c8a146)
#24 0x0000000006c45ce6 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6c45ce6)
#25 0x0000000006c46bd5 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6c46bd5)
#26 0x0000000006c27aba clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6c27aba)
#27 0x0000000004e44b58 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4e44b58)
#28 0x000000000517d638 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x517d638)
#29 0x00000000050f936d clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x50f936d)
#30 0x000000000527c1bd clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x527c1bd)
#31 0x0000000000dcc82c cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdcc82c)
#32 0x0000000000dc350a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>) driver.cpp:0:0
#33 0x0000000000dc368d int llvm::function_ref<int (llvm::SmallVectorImpl<char const*>&)>::callback_fn<clang_main(int, char**, llvm::ToolContext const&)::'lambda'(llvm::SmallVectorImpl<char const*>&)>(long, llvm::SmallVectorImpl<char const*>&) driver.cpp:0:0
#34 0x0000000004eb7b59 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::'lambda'()>(long) Job.cpp:0:0
#35 0x00000000042873b4 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x42873b4)
#36 0x0000000004eb81a6 clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0
#37 0x0000000004e74b42 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4e74b42)
#38 0x0000000004e75aee clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4e75aee)
#39 0x0000000004e7d325 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4e7d325)
#40 0x0000000000dc8da2 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdc8da2)
#41 0x0000000000cc8a4a main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xcc8a4a)
#42 0x000073046462a1ca (/lib/x86_64-linux-gnu/libc.so.6+0x2a1ca)
#43 0x000073046462a28b __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a28b)
#44 0x0000000000dc2eb5 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdc2eb5)
clang++: error: clang frontend command failed due to signal (use -v to see invocation)
Compiler returned: 134

k-arrows avatar Jun 18 '26 11:06 k-arrows

@llvm/issue-subscribers-clang-frontend

Author: k-arrows

Reproducer: https://godbolt.org/z/vb5zPof51 ```cpp template <typename T> struct A { void B { int y = 0; }; template <typename U> int x = 0; }

template <typename U> struct A<long>::B<U &> { }; template <typename U> int A<int>::x = 3; template <> template <typename U> int A<int>::x<U &> = 4;

static_assert(A<long>::x<int &> == 5);


Backtrace:
```console
clang++: /root/llvm-project/llvm/tools/clang/lib/Sema/SemaLookup.cpp:1809: bool hasAcceptableMemberSpecialization(clang::Sema&amp;, const clang::NamedDecl*, llvm::SmallVectorImpl&lt;clang::Module*&gt;*, clang::Sema::AcceptableKind): Assertion `isa&lt;CXXRecordDecl&gt;(D-&gt;getDeclContext()) &amp;&amp; "not a member specialization"' 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 -std=c++20 &lt;source&gt;
1.	&lt;source&gt;:12:33: current parser token '=='
 #<!-- -->0 0x000000000434c4d8 llvm::sys::PrintStackTrace(llvm::raw_ostream&amp;, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x434c4d8)
 #<!-- -->1 0x0000000004349414 llvm::sys::RunSignalHandlers() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4349414)
 #<!-- -->2 0x0000000004349a34 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4349a34)
 #<!-- -->3 0x0000000004286f78 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #<!-- -->4 0x0000730464645330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
 #<!-- -->5 0x000073046469eb2c pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x9eb2c)
 #<!-- -->6 0x000073046464527e raise (/lib/x86_64-linux-gnu/libc.so.6+0x4527e)
 #<!-- -->7 0x00007304646288ff abort (/lib/x86_64-linux-gnu/libc.so.6+0x288ff)
 #<!-- -->8 0x000073046462881b (/lib/x86_64-linux-gnu/libc.so.6+0x2881b)
 #<!-- -->9 0x000073046463b517 (/lib/x86_64-linux-gnu/libc.so.6+0x3b517)
#<!-- -->10 0x000000000734e4e4 (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x734e4e4)
#<!-- -->11 0x000000000764a054 (anonymous namespace)::ExplicitSpecializationVisibilityChecker::check(clang::NamedDecl*) (.constprop.0) SemaTemplate.cpp:0:0
#<!-- -->12 0x000000000764a33b clang::Sema::checkSpecializationReachability(clang::SourceLocation, clang::NamedDecl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x764a33b)
#<!-- -->13 0x000000000767249a clang::Sema::CheckVarTemplateId(clang::VarTemplateDecl*, clang::SourceLocation, clang::SourceLocation, clang::TemplateArgumentListInfo const&amp;, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x767249a)
#<!-- -->14 0x0000000007672e44 clang::Sema::CheckVarTemplateId(clang::CXXScopeSpec const&amp;, clang::DeclarationNameInfo const&amp;, clang::VarTemplateDecl*, clang::NamedDecl*, clang::SourceLocation, clang::TemplateArgumentListInfo const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7672e44)
#<!-- -->15 0x00000000076730a7 clang::Sema::BuildTemplateIdExpr(clang::CXXScopeSpec const&amp;, clang::SourceLocation, clang::LookupResult&amp;, bool, clang::TemplateArgumentListInfo const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x76730a7)
#<!-- -->16 0x00000000071a0878 clang::Sema::ActOnIdExpression(clang::Scope*, clang::CXXScopeSpec&amp;, clang::SourceLocation, clang::UnqualifiedId&amp;, bool, bool, clang::CorrectionCandidateCallback*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x71a0878)
#<!-- -->17 0x0000000006cd3501 clang::Parser::tryParseCXXIdExpression(clang::CXXScopeSpec&amp;, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6cd3501)
#<!-- -->18 0x0000000006cd379e clang::Parser::ParseCXXIdExpression(bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6cd379e)
#<!-- -->19 0x0000000006cb7934 clang::Parser::ParseCastExpression(clang::CastParseKind, bool, bool&amp;, clang::TypoCorrectionTypeBehavior, bool, bool*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6cb7934)
#<!-- -->20 0x0000000006cb7210 clang::Parser::ParseCastExpression(clang::CastParseKind, bool, bool&amp;, clang::TypoCorrectionTypeBehavior, bool, bool*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6cb7210)
#<!-- -->21 0x0000000006cc410e clang::Parser::ParseConstantExpressionInExprEvalContext(clang::TypoCorrectionTypeBehavior) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6cc410e)
#<!-- -->22 0x0000000006c9b8a6 clang::Parser::ParseStaticAssertDeclaration(clang::SourceLocation&amp;) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6c9b8a6)
#<!-- -->23 0x0000000006c8a146 clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&amp;, clang::ParsedAttributes&amp;, clang::ParsedAttributes&amp;, clang::SourceLocation*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6c8a146)
#<!-- -->24 0x0000000006c45ce6 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&amp;, clang::ParsedAttributes&amp;, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6c45ce6)
#<!-- -->25 0x0000000006c46bd5 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr&lt;clang::DeclGroupRef&gt;&amp;, clang::Sema::ModuleImportState&amp;) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6c46bd5)
#<!-- -->26 0x0000000006c27aba clang::ParseAST(clang::Sema&amp;, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6c27aba)
#<!-- -->27 0x0000000004e44b58 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4e44b58)
#<!-- -->28 0x000000000517d638 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x517d638)
#<!-- -->29 0x00000000050f936d clang::CompilerInstance::ExecuteAction(clang::FrontendAction&amp;) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x50f936d)
#<!-- -->30 0x000000000527c1bd clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x527c1bd)
#<!-- -->31 0x0000000000dcc82c cc1_main(llvm::ArrayRef&lt;char const*&gt;, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdcc82c)
#<!-- -->32 0x0000000000dc350a ExecuteCC1Tool(llvm::SmallVectorImpl&lt;char const*&gt;&amp;, llvm::ToolContext const&amp;, llvm::IntrusiveRefCntPtr&lt;llvm::vfs::FileSystem&gt;) driver.cpp:0:0
#<!-- -->33 0x0000000000dc368d int llvm::function_ref&lt;int (llvm::SmallVectorImpl&lt;char const*&gt;&amp;)&gt;::callback_fn&lt;clang_main(int, char**, llvm::ToolContext const&amp;)::'lambda'(llvm::SmallVectorImpl&lt;char const*&gt;&amp;)&gt;(long, llvm::SmallVectorImpl&lt;char const*&gt;&amp;) driver.cpp:0:0
#<!-- -->34 0x0000000004eb7b59 void llvm::function_ref&lt;void ()&gt;::callback_fn&lt;clang::driver::CC1Command::Execute(llvm::ArrayRef&lt;std::optional&lt;llvm::StringRef&gt;&gt;, std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt;&gt;*, bool*) const::'lambda'()&gt;(long) Job.cpp:0:0
#<!-- -->35 0x00000000042873b4 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref&lt;void ()&gt;) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x42873b4)
#<!-- -->36 0x0000000004eb81a6 clang::driver::CC1Command::Execute(llvm::ArrayRef&lt;std::optional&lt;llvm::StringRef&gt;&gt;, std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt;&gt;*, bool*) const (.part.0) Job.cpp:0:0
#<!-- -->37 0x0000000004e74b42 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&amp;, clang::driver::Command const*&amp;, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4e74b42)
#<!-- -->38 0x0000000004e75aee clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&amp;, llvm::SmallVectorImpl&lt;std::pair&lt;int, clang::driver::Command const*&gt;&gt;&amp;, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4e75aee)
#<!-- -->39 0x0000000004e7d325 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&amp;, llvm::SmallVectorImpl&lt;std::pair&lt;int, clang::driver::Command const*&gt;&gt;&amp;) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4e7d325)
#<!-- -->40 0x0000000000dc8da2 clang_main(int, char**, llvm::ToolContext const&amp;) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdc8da2)
#<!-- -->41 0x0000000000cc8a4a main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xcc8a4a)
#<!-- -->42 0x000073046462a1ca (/lib/x86_64-linux-gnu/libc.so.6+0x2a1ca)
#<!-- -->43 0x000073046462a28b __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a28b)
#<!-- -->44 0x0000000000dc2eb5 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdc2eb5)
clang++: error: clang frontend command failed due to signal (use -v to see invocation)
Compiler returned: 134

this does not crash with clang-22: https://godbolt.org/z/KdrrP9MoK

k-arrows avatar Jun 18 '26 11:06 k-arrows

Bisects to f505ceabdd2339f078cd6886d3f52cc622abd5c9 @mizvekov .

MagentaTreehouse avatar Jun 18 '26 13:06 MagentaTreehouse