Skip to content

Commit 581fa32

Browse files
authored
Merge pull request #8651 from apple/eng/fix-ptrauth-after-merge
Fix ptrauth after merge
2 parents 9e3338c + 122a553 commit 581fa32

File tree

5 files changed

+37
-4
lines changed

5 files changed

+37
-4
lines changed

clang/lib/CodeGen/CGCXXABI.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,12 @@ class CGCXXABI {
471471
BaseSubobject Base,
472472
const CXXRecordDecl *NearestVBase) = 0;
473473

474+
/// Get the address point of the vtable for the given base subobject while
475+
/// building a constexpr.
476+
virtual llvm::Constant *
477+
getVTableAddressPointForConstExpr(BaseSubobject Base,
478+
const CXXRecordDecl *VTableClass) = 0;
479+
474480
/// Get the address of the vtable for the given record decl which should be
475481
/// used for the vptr at the given offset in RD.
476482
virtual llvm::GlobalVariable *getAddrOfVTable(const CXXRecordDecl *RD,

clang/lib/CodeGen/CGExprConstant.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -801,8 +801,8 @@ bool ConstStructBuilder::Build(const APValue &Val, const RecordDecl *RD,
801801
// Add a vtable pointer, if we need one and it hasn't already been added.
802802
if (Layout.hasOwnVFPtr()) {
803803
llvm::Constant *VTableAddressPoint =
804-
CGM.getCXXABI().getVTableAddressPoint(BaseSubobject(CD, Offset),
805-
VTableClass);
804+
CGM.getCXXABI().getVTableAddressPointForConstExpr(
805+
BaseSubobject(CD, Offset), VTableClass);
806806
if (!AppendBytes(Offset, VTableAddressPoint))
807807
return false;
808808
}

clang/lib/CodeGen/ItaniumCXXABI.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,10 @@ class ItaniumCXXABI : public CodeGen::CGCXXABI {
308308
CodeGenFunction &CGF, const CXXRecordDecl *VTableClass,
309309
BaseSubobject Base, const CXXRecordDecl *NearestVBase);
310310

311+
llvm::Constant *
312+
getVTableAddressPointForConstExpr(BaseSubobject Base,
313+
const CXXRecordDecl *VTableClass) override;
314+
311315
llvm::GlobalVariable *getAddrOfVTable(const CXXRecordDecl *RD,
312316
CharUnits VPtrOffset) override;
313317

@@ -2088,6 +2092,18 @@ llvm::Value *ItaniumCXXABI::getVTableAddressPointInStructorWithVTT(
20882092
return AP;
20892093
}
20902094

2095+
llvm::Constant *
2096+
ItaniumCXXABI::getVTableAddressPointForConstExpr(BaseSubobject Base,
2097+
const CXXRecordDecl *VTableClass) {
2098+
auto AP = getVTableAddressPoint(Base, VTableClass);
2099+
2100+
if (auto &Schema = CGM.getCodeGenOpts().PointerAuth.CXXVTablePointers)
2101+
AP = CGM.getConstantSignedPointer(AP, Schema, nullptr, GlobalDecl(),
2102+
QualType());
2103+
2104+
return AP;
2105+
}
2106+
20912107
llvm::GlobalVariable *ItaniumCXXABI::getAddrOfVTable(const CXXRecordDecl *RD,
20922108
CharUnits VPtrOffset) {
20932109
assert(VPtrOffset.isZero() && "Itanium ABI only supports zero vptr offsets");

clang/lib/CodeGen/MicrosoftCXXABI.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,10 @@ class MicrosoftCXXABI : public CGCXXABI {
327327
CodeGenFunction &CGF, const CXXRecordDecl *VTableClass,
328328
BaseSubobject Base, const CXXRecordDecl *NearestVBase) override;
329329

330+
llvm::Constant *
331+
getVTableAddressPointForConstExpr(BaseSubobject Base,
332+
const CXXRecordDecl *VTableClass) override;
333+
330334
llvm::GlobalVariable *getAddrOfVTable(const CXXRecordDecl *RD,
331335
CharUnits VPtrOffset) override;
332336

@@ -1788,6 +1792,13 @@ MicrosoftCXXABI::getVTableAddressPoint(BaseSubobject Base,
17881792
return VFTablesMap[ID];
17891793
}
17901794

1795+
llvm::Constant *MicrosoftCXXABI::getVTableAddressPointForConstExpr(
1796+
BaseSubobject Base, const CXXRecordDecl *VTableClass) {
1797+
llvm::Constant *VFTable = getVTableAddressPoint(Base, VTableClass);
1798+
assert(VFTable && "Couldn't find a vftable for the given base?");
1799+
return VFTable;
1800+
}
1801+
17911802
llvm::GlobalVariable *MicrosoftCXXABI::getAddrOfVTable(const CXXRecordDecl *RD,
17921803
CharUnits VPtrOffset) {
17931804
// getAddrOfVTable may return 0 if asked to get an address of a vtable which

clang/test/CodeGen/ptrauth-debuginfo.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ extern int external_int;
88
// CHECK: !DIDerivedType(tag: DW_TAG_LLVM_ptrauth_type,
99
// CHECK-SAME: ptrAuthKey: 1,
1010
// CHECK-SAME: ptrAuthIsAddressDiscriminated: false,
11-
// CHECK-SAME: ptrAuthExtraDiscriminator: 1234)
11+
// CHECK-SAME: ptrAuthExtraDiscriminator: 1234,
1212
int * __ptrauth(1,0,1234) g1 = &external_int;
1313

1414
struct A {
@@ -23,4 +23,4 @@ void f() {
2323
// CHECK: !DIDerivedType(tag: DW_TAG_LLVM_ptrauth_type,
2424
// CHECK-SAME: ptrAuthKey: 1,
2525
// CHECK-SAME: ptrAuthIsAddressDiscriminated: true,
26-
// CHECK-SAME: ptrAuthExtraDiscriminator: 1)
26+
// CHECK-SAME: ptrAuthExtraDiscriminator: 1,

0 commit comments

Comments
 (0)