Skip to content

Commit 9647a86

Browse files
authored
[CIR] Finish record layout for classes with virtual bases (#156770)
There was a small piece left unimplemented for classes with a primary virtual base. This adds that implementation.
1 parent b45582f commit 9647a86

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
@@ -961,8 +961,9 @@ void CIRRecordLowering::computeVolatileBitfields() {
961961
void CIRRecordLowering::accumulateBases() {
962962
// If we've got a primary virtual base, we need to add it with the bases.
963963
if (astRecordLayout.isPrimaryBaseVirtual()) {
964-
cirGenTypes.getCGModule().errorNYI(recordDecl->getSourceRange(),
965-
"accumulateBases: primary virtual base");
964+
const CXXRecordDecl *baseDecl = astRecordLayout.getPrimaryBase();
965+
members.push_back(MemberInfo(CharUnits::Zero(), MemberInfo::InfoKind::Base,
966+
getStorageType(baseDecl), baseDecl));
966967
}
967968

968969
// 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)