Skip to content

Commit ff4ba5d

Browse files
committed
[CIR] Finish record layout for classes with virtual bases
There was a small piece left unimplemented for classes with a primary virtual base. This adds that implementation.
1 parent 88c3825 commit ff4ba5d

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

clang/lib/CIR/CodeGen/CIRGenRecordLayoutBuilder.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -913,8 +913,9 @@ void CIRRecordLowering::computeVolatileBitfields() {
913913
void CIRRecordLowering::accumulateBases() {
914914
// If we've got a primary virtual base, we need to add it with the bases.
915915
if (astRecordLayout.isPrimaryBaseVirtual()) {
916-
cirGenTypes.getCGModule().errorNYI(recordDecl->getSourceRange(),
917-
"accumulateBases: primary virtual base");
916+
const CXXRecordDecl *baseDecl = astRecordLayout.getPrimaryBase();
917+
members.push_back(MemberInfo(CharUnits::Zero(), MemberInfo::InfoKind::Base,
918+
getStorageType(baseDecl), baseDecl));
918919
}
919920

920921
// Accumulate the non-virtual bases.

clang/test/CIR/CodeGen/vbase.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,29 @@
55
// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -emit-llvm %s -o %t.ll
66
// RUN: FileCheck --input-file=%t.ll %s --check-prefix=OGCG
77

8+
// Test the record layout for a class with a primary virtual base.
9+
class Base {
10+
public:
11+
virtual void f();
12+
};
13+
14+
class Derived : public virtual Base {};
15+
16+
// This is just here to force the record types to be emitted.
17+
void f() {
18+
Derived d;
19+
}
20+
21+
// CIR: !rec_Base = !cir.record<class "Base" {!cir.vptr}>
22+
// CIR: !rec_Derived = !cir.record<class "Derived" {!rec_Base}>
23+
24+
// LLVM: %class.Derived = type { %class.Base }
25+
// LLVM: %class.Base = type { ptr }
26+
27+
// OGCG: %class.Derived = type { %class.Base }
28+
// OGCG: %class.Base = type { ptr }
29+
30+
// Test the constructor handling for a class with a virtual base.
831
struct A {
932
int a;
1033
};

0 commit comments

Comments
 (0)