Issue 91131
Summary Assertion `CXXInfo->BaseOffsets.count(Base) && "Did not find base!"` failed
Labels c++, clang:frontend, crash-on-invalid
Assignees
Reporter Endilll
    While reducing #63250, I stumbled upon the following crash (https://godbolt.org/z/84b6WTans):
```cpp
template <typename T>
struct _Copy_ctor_base : T {};

template <typename _Types>
struct _Variant_base : _Copy_ctor_base<_Types> {};

struct monostate {};

template <>
struct monostate {};

_Variant_base<monostate> v;
```
Clang 19.0 crash:
```
<source>:9:1: error: extraneous 'template<>' in declaration of struct 'monostate'
    9 | template <>
      | ^
<source>:10:8: error: specialization of member 'monostate' does not specialize an instantiated member
   10 | struct monostate {};
      | ^
<source>:7:8: note: attempt to specialize declaration here
    7 | struct monostate {};
      |        ^
<source>:2:8: error: implicit default constructor for '_Copy_ctor_base<monostate>' must explicitly initialize the base class 'monostate' which does not have a default constructor
    2 | struct _Copy_ctor_base : T {};
      | ^
<source>:5:8: note: in implicit default constructor for '_Copy_ctor_base<monostate>' first required here
    5 | struct _Variant_base : _Copy_ctor_base<_Types> {};
      | ^
<source>:12:26: note: in implicit default constructor for '_Variant_base<monostate>' first required here
   12 | _Variant_base<monostate> v;
      | ^
<source>:7:8: note: 'monostate' declared here
    7 | struct monostate {};
      |        ^

clang++: /root/llvm-project/clang/include/clang/AST/RecordLayout.h:253:
clang::CharUnits clang::ASTRecordLayout::getBaseClassOffset(const clang::CXXRecordDecl*) const:
Assertion `CXXInfo->BaseOffsets.count(Base) && "Did not find base!"' 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++ -gdwarf-4 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics -std=c++98 <source>
1.	<source>:12:27: current parser token ';'
 #0 0x0000000003979978 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3979978)
 #1 0x000000000397765c llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x397765c)
 #2 0x00000000038c9018 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x000073bd3f842520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x000073bd3f8969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #5 0x000073bd3f842476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #6 0x000073bd3f8287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #7 0x000073bd3f82871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
 #8 0x000073bd3f839e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
 #9 0x0000000003e0b6bf clang::ASTRecordLayout::getBaseClassOffset(clang::CXXRecordDecl const*) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3e0b6bf)
#10 0x00000000077d1c8a (anonymous namespace)::EmptySubobjectMap::CanPlaceBaseSubobjectAtOffset((anonymous namespace)::BaseSubobjectInfo const*, clang::CharUnits) RecordLayoutBuilder.cpp:0:0
#11 0x00000000077d1e2e (anonymous namespace)::EmptySubobjectMap::CanPlaceBaseAtOffset((anonymous namespace)::BaseSubobjectInfo const*, clang::CharUnits) RecordLayoutBuilder.cpp:0:0
#12 0x00000000077d212e (anonymous namespace)::ItaniumRecordLayoutBuilder::LayoutBase((anonymous namespace)::BaseSubobjectInfo const*) RecordLayoutBuilder.cpp:0:0
#13 0x00000000077d24c1 (anonymous namespace)::ItaniumRecordLayoutBuilder::LayoutNonVirtualBase((anonymous namespace)::BaseSubobjectInfo const*) RecordLayoutBuilder.cpp:0:0
#14 0x00000000077cbcdd clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x77cbcdd)
#15 0x00000000072de1a2 clang::ASTContext::getTypeInfoImpl(clang::Type const*) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x72de1a2)
#16 0x00000000072c6187 clang::ASTContext::getTypeInfo(clang::Type const*) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x72c6187)
#17 0x00000000072dd257 clang::ASTContext::getTypeAlignInChars(clang::QualType) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x72dd257)
#18 0x00000000064820c3 clang::Sema::CheckArgAlignment(clang::SourceLocation, clang::NamedDecl*, llvm::StringRef, clang::QualType, clang::QualType) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x64820c3)
#19 0x00000000064ae26a clang::Sema::CheckConstructorCall(clang::FunctionDecl*, clang::QualType, llvm::ArrayRef<clang::Expr const*>, clang::FunctionProtoType const*, clang::SourceLocation) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x64ae26a)
#20 0x00000000066b738c clang::Sema::CompleteConstructorCall(clang::CXXConstructorDecl*, clang::QualType, llvm::MutableArrayRef<clang::Expr*>, clang::SourceLocation, llvm::SmallVectorImpl<clang::Expr*>&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x66b738c)
#21 0x0000000006a2a3ac PerformConstructorInitialization(clang::Sema&, clang::InitializedEntity const&, clang::InitializationKind const&, llvm::MutableArrayRef<clang::Expr*>, clang::InitializationSequence::Step const&, bool&, bool, bool, clang::SourceLocation, clang::SourceLocation) SemaInit.cpp:0:0
#22 0x0000000006a3ede6 clang::InitializationSequence::Perform(clang::Sema&, clang::InitializedEntity const&, clang::InitializationKind const&, llvm::MutableArrayRef<clang::Expr*>, clang::QualType*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6a3ede6)
#23 0x000000000660ea8b clang::Sema::ActOnUninitializedDecl(clang::Decl*) (.part.0) SemaDecl.cpp:0:0
#24 0x00000000062bd9f4 clang::Parser::ParseDeclarationAfterDeclaratorAndAttributes(clang::Declarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x62bd9f4)
#25 0x00000000062cdc4a 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+++0x62cdc4a)
#26 0x0000000006289b0e clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6289b0e)
#27 0x000000000628a303 clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x628a303)
#28 0x0000000006290907 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6290907)
#29 0x00000000062917bf clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x62917bf)
#30 0x000000000628527a clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x628527a)
#31 0x0000000004246e08 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4246e08)
#32 0x00000000044c8199 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x44c8199)
#33 0x000000000445025e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x445025e)
#34 0x00000000045aef3e clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x45aef3e)
#35 0x0000000000c4fdec cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xc4fdec)
#36 0x0000000000c4907a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#37 0x000000000428a649 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
#38 0x00000000038c94c4 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x38c94c4)
#39 0x000000000428ac3f 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
#40 0x0000000004250fd5 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4250fd5)
#41 0x0000000004251a3d 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+++0x4251a3d)
#42 0x00000000042597c5 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x42597c5)
#43 0x0000000000c4d285 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xc4d285)
#44 0x0000000000b2f354 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xb2f354)
#45 0x000073bd3f829d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#46 0x000073bd3f829e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#47 0x0000000000c48b6e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xc48b6e)
clang++: error: clang frontend command failed with exit code 134 (use -v to see invocation)
Compiler returned: 134
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to