Skip to content

Commit ec7bd37

Browse files
ChuanqiXu9llvmbot
authored andcommitted
[C++20] [Modules] Don't insert class not in named modules to PendingEmittingVTables (#106501)
Close #102933 The root cause of the issue is an oversight in #102287 that I didn't notice that PendingEmittingVTables should only accept classes in named modules. (cherry picked from commit 47615ff)
1 parent 5f744ee commit ec7bd37

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

clang/include/clang/Serialization/ASTWriter.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -500,8 +500,8 @@ class ASTWriter : public ASTDeserializationListener,
500500
std::vector<SourceRange> NonAffectingRanges;
501501
std::vector<SourceLocation::UIntTy> NonAffectingOffsetAdjustments;
502502

503-
/// A list of classes which need to emit the VTable in the corresponding
504-
/// object file.
503+
/// A list of classes in named modules which need to emit the VTable in
504+
/// the corresponding object file.
505505
llvm::SmallVector<CXXRecordDecl *> PendingEmittingVTables;
506506

507507
/// Computes input files that didn't affect compilation of the current module,

clang/lib/Serialization/ASTWriter.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3963,6 +3963,9 @@ void ASTWriter::WriteIdentifierTable(Preprocessor &PP,
39633963
}
39643964

39653965
void ASTWriter::handleVTable(CXXRecordDecl *RD) {
3966+
if (!RD->isInNamedModule())
3967+
return;
3968+
39663969
PendingEmittingVTables.push_back(RD);
39673970
}
39683971

clang/test/Modules/pr106483.cppm

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// RUN: rm -rf %t
2+
// RUN: mkdir -p %t
3+
// RUN: split-file %s %t
4+
//
5+
// RUN: %clang_cc1 -std=c++23 %t/a.cppm -emit-module-interface -o %t/a.pcm
6+
// RUN: %clang_cc1 -std=c++23 %t/b.cppm -emit-module-interface -o %t/b.pcm \
7+
// RUN: -fprebuilt-module-path=%t
8+
// RUN: %clang_cc1 -std=c++23 -fprebuilt-module-path=%t %t/b.pcm -emit-llvm \
9+
// RUN: -disable-llvm-passes -o - | FileCheck %t/b.cppm
10+
11+
//--- a.cppm
12+
module;
13+
14+
struct base {
15+
virtual void f() const;
16+
};
17+
18+
inline void base::f() const {
19+
}
20+
21+
export module a;
22+
export using ::base;
23+
24+
//--- b.cppm
25+
module;
26+
27+
struct base {
28+
virtual void f() const;
29+
};
30+
31+
inline void base::f() const {
32+
}
33+
34+
export module b;
35+
import a;
36+
export using ::base;
37+
38+
export extern "C" void func() {}
39+
40+
// We only need to check that the IR are successfully emitted instead of crash.
41+
// CHECK: func

0 commit comments

Comments
 (0)