Skip to content

[clang][Modules] Assertion failure with out-of-line definition of virtual function in global module fragment of two modules #102933

Closed
@davidstone

Description

@davidstone

The following valid translation units

module;

struct base {
    virtual void f() const;
};

inline void base::f() const {
}

export module a;
module;

struct base {
    virtual void f() const;
};

inline void base::f() const {
}

export module b;

import a;

Cause clang to crash with

/opt/compiler-explorer/clang-assertions-trunk/bin/clang++ --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot   -fcolor-diagnostics -fno-crash-diagnostics -std=c++23 -MD -MT CMakeFiles/bug.dir/b.cpp.o -MF CMakeFiles/bug.dir/b.cpp.o.d @CMakeFiles/bug.dir/b.cpp.o.modmap -o CMakeFiles/bug.dir/b.cpp.o -c /app/b.cpp
clang-20: /root/llvm-project/clang/lib/AST/VTableBuilder.cpp:186: {anonymous}::FinalOverriders::FinalOverriders(const clang::CXXRecordDecl*, clang::CharUnits, const clang::CXXRecordDecl*): Assertion `SubobjectOffsets.count(std::make_pair(MD->getParent(), SubobjectNumber)) && "Did not find subobject offset!"' 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-20240812/bin/clang-20 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -disable-free -clear-ast-before-backend -main-file-name b.cpp -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/app/build -fcoverage-compilation-dir=/app/build -resource-dir /opt/compiler-explorer/clang-assertions-trunk-20240812/lib/clang/20 -std=c++23 -fdeprecated-macro -ferror-limit 19 -fgnuc-version=4.2.1 -fno-implicit-modules -fmodule-file=a=CMakeFiles/bug.dir/a.pcm -fskip-odr-check-in-gmf -fcxx-exceptions -fexceptions -fcolor-diagnostics -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o CMakeFiles/bug.dir/b.cpp.o -x pcm CMakeFiles/bug.dir/b.pcm
1.	<eof> parser at end of file
 #0 0x0000000003abec78 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk-20240812/bin/clang-20+0x3abec78)
 #1 0x0000000003abc3ec SignalHandler(int) Signals.cpp:0:0
 #2 0x000075a426e42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #3 0x000075a426e969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #4 0x000075a426e42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #5 0x000075a426e287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #6 0x000075a426e2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
 #7 0x000075a426e39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
 #8 0x0000000007c5b9bf (anonymous namespace)::FinalOverriders::FinalOverriders(clang::CXXRecordDecl const*, clang::CharUnits, clang::CXXRecordDecl const*) VTableBuilder.cpp:0:0
 #9 0x0000000007c6b832 clang::ItaniumVTableContext::computeVTableRelatedInformation(clang::CXXRecordDecl const*) (/opt/compiler-explorer/clang-assertions-trunk-20240812/bin/clang-20+0x7c6b832)
#10 0x0000000003f803e6 clang::ItaniumVTableContext::getVTableLayout(clang::CXXRecordDecl const*) (/opt/compiler-explorer/clang-assertions-trunk-20240812/bin/clang-20+0x3f803e6)
#11 0x0000000003f83769 (anonymous namespace)::ItaniumCXXABI::getAddrOfVTable(clang::CXXRecordDecl const*, clang::CharUnits) ItaniumCXXABI.cpp:0:0
#12 0x0000000003f84ca4 (anonymous namespace)::ItaniumCXXABI::emitVTableDefinitions(clang::CodeGen::CodeGenVTables&, clang::CXXRecordDecl const*) ItaniumCXXABI.cpp:0:0
#13 0x00000000047e8441 clang::ASTReader::PassInterestingDeclsToConsumer() (/opt/compiler-explorer/clang-assertions-trunk-20240812/bin/clang-20+0x47e8441)
#14 0x000000000474861e non-virtual thunk to clang::ASTReader::StartTranslationUnit(clang::ASTConsumer*) (/opt/compiler-explorer/clang-assertions-trunk-20240812/bin/clang-20+0x474861e)
#15 0x00000000064d14f5 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk-20240812/bin/clang-20+0x64d14f5)
#16 0x00000000043d17a8 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk-20240812/bin/clang-20+0x43d17a8)
#17 0x000000000465d6d9 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk-20240812/bin/clang-20+0x465d6d9)
#18 0x00000000045e1cde clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk-20240812/bin/clang-20+0x45e1cde)
#19 0x0000000004746a4e clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk-20240812/bin/clang-20+0x4746a4e)
#20 0x0000000000c8fe2f cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk-20240812/bin/clang-20+0xc8fe2f)
#21 0x0000000000c88fba ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#22 0x0000000000c8c8ee clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk-20240812/bin/clang-20+0xc8c8ee)
#23 0x0000000000b612d4 main (/opt/compiler-explorer/clang-assertions-trunk-20240812/bin/clang-20+0xb612d4)
#24 0x000075a426e29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#25 0x000075a426e29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#26 0x0000000000c88a6e _start (/opt/compiler-explorer/clang-assertions-trunk-20240812/bin/clang-20+0xc88a6e)
clang++: error: unable to execute command: Aborted (core dumped)
clang++: error: clang frontend command failed due to signal (use -v to see invocation)

See it live: https://godbolt.org/z/GoPr45qWK

This also means that no more than one module in a project can include Boost.System headers.

Metadata

Metadata

Assignees

Labels

clang:modulesC++20 modules and Clang Header Modules

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions