Skip to content

Commit 884f3d8

Browse files
bcardosolopeslanza
authored andcommitted
[CIR][CIRGen] Bring getAddressOfBaseClass a bit closer to OG
1 parent 7a83dad commit 884f3d8

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

clang/lib/CIR/CodeGen/CIRGenClass.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1572,10 +1572,12 @@ CIRGenFunction::getAddressOfBaseClass(Address Value,
15721572

15731573
// If there is no virtual base, use cir.base_class_addr. It takes care of
15741574
// the adjustment and the null pointer check.
1575-
if (!VBase) {
1575+
if (NonVirtualOffset.isZero() && !VBase) {
15761576
if (sanitizePerformTypeCheck()) {
15771577
llvm_unreachable("NYI: sanitizePerformTypeCheck");
15781578
}
1579+
return builder.createBaseClassAddr(getLoc(Loc), Value, BaseValueTy, 0,
1580+
/*assumeNotNull=*/true);
15791581
}
15801582

15811583
if (sanitizePerformTypeCheck()) {

clang/test/CIR/CodeGen/derived-cast.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ A *B::getAsA() {
2626
// CIR: %[[VAL_2:.*]] = cir.alloca !cir.ptr<!ty_A>, !cir.ptr<!cir.ptr<!ty_A>>, ["__retval"] {alignment = 8 : i64}
2727
// CIR: %[[VAL_3:.*]] = cir.load %[[VAL_1]] : !cir.ptr<!cir.ptr<!ty_B>>, !cir.ptr<!ty_B>
2828
// CIR: %[[VAL_4:.*]] = cir.derived_class_addr(%[[VAL_3]] : !cir.ptr<!ty_B> nonnull) [4] -> !cir.ptr<!ty_X>
29-
// CIR: %[[VAL_5:.*]] = cir.base_class_addr(%[[VAL_4]] : !cir.ptr<!ty_X>) [0] -> !cir.ptr<!ty_A>
29+
// CIR: %[[VAL_5:.*]] = cir.base_class_addr(%[[VAL_4]] : !cir.ptr<!ty_X> nonnull) [0] -> !cir.ptr<!ty_A>
3030
// CIR: cir.store %[[VAL_5]], %[[VAL_2]] : !cir.ptr<!ty_A>, !cir.ptr<!cir.ptr<!ty_A>>
3131
// CIR: %[[VAL_6:.*]] = cir.load %[[VAL_2]] : !cir.ptr<!cir.ptr<!ty_A>>, !cir.ptr<!ty_A>
3232
// CIR: cir.return %[[VAL_6]] : !cir.ptr<!ty_A>

0 commit comments

Comments
 (0)