Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ Non-comprehensive list of changes in this release
- Support parsing the `cc` operand modifier and alias it to the `c` modifier (#GH127719).
- Added `__builtin_elementwise_exp10`.
- For AMDPGU targets, added `__builtin_v_cvt_off_f32_i4` that maps to the `v_cvt_off_f32_i4` instruction.
- Support authenticated ``type_info`` vtable pointers in Objective-C++

New Compiler Flags
------------------
Expand Down
3 changes: 3 additions & 0 deletions clang/include/clang/CodeGen/ConstantInitBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@ class ConstantAggregateBuilderBase {
void addSignedPointer(llvm::Constant *Pointer,
const PointerAuthSchema &Schema, GlobalDecl CalleeDecl,
QualType CalleeType);
void addSignedPointer(llvm::Constant *Pointer, unsigned Key,
bool UseAddressDiscrimination,
llvm::ConstantInt *OtherDiscriminator);

/// Add a null pointer of a specific type.
void addNullPointer(llvm::PointerType *ptrTy) {
Expand Down
20 changes: 18 additions & 2 deletions clang/lib/CodeGen/CGObjCMac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7676,10 +7676,26 @@ CGObjCNonFragileABIMac::GetInterfaceEHType(const ObjCInterfaceDecl *ID,
}

llvm::Value *VTableIdx = llvm::ConstantInt::get(CGM.Int32Ty, 2);
llvm::Constant *VTablePtr = llvm::ConstantExpr::getInBoundsGetElementPtr(
VTableGV->getValueType(), VTableGV, VTableIdx);

ConstantInitBuilder builder(CGM);
auto values = builder.beginStruct(ObjCTypes.EHTypeTy);
values.add(llvm::ConstantExpr::getInBoundsGetElementPtr(
VTableGV->getValueType(), VTableGV, VTableIdx));

if (auto &Schema =
CGM.getCodeGenOpts().PointerAuth.CXXTypeInfoVTablePointer) {
uint32_t discrimination = 0;
if (Schema.hasOtherDiscrimination()) {
assert(Schema.getOtherDiscrimination() ==
PointerAuthSchema::Discrimination::Constant);
discrimination = Schema.getConstantDiscrimination();
}
values.addSignedPointer(
VTablePtr, Schema.getKey(), Schema.isAddressDiscriminated(),
llvm::ConstantInt::get(CGM.IntPtrTy, discrimination));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can just call the addSignedPointer variant that takes a schema and pass null values for the decl and type.

Copy link
Contributor Author

@ojhunt ojhunt Jun 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

50/50 this code predates us having that function \o/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, we can't use the general schema version as it requires the type we're constructing a field for, but we construct the type_info vtable discriminator manually from constants because we don't necessarily actually have the actually type_info type available.

Copy link
Contributor

@rjmccall rjmccall Jun 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand that we can't use the generic v-table pointer schema. But CXXTypeInfoVTablePointer has a hard-coded constant in it, which should be fine to use without a decl or type, and I'd like to avoid having an extra place that destructures a PointerAuthSchema the way this code is doing.

} else {
values.add(VTablePtr);
}
values.add(GetClassName(ClassName));
values.add(GetClassGlobal(ID, /*metaclass*/ false, NotForDefinition));

Expand Down
12 changes: 12 additions & 0 deletions clang/lib/CodeGen/ConstantInitBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,3 +314,15 @@ void ConstantAggregateBuilderBase::addSignedPointer(
Pointer, Schema, StorageAddress, CalleeDecl, CalleeType);
add(SignedPointer);
}

void ConstantAggregateBuilderBase::addSignedPointer(
llvm::Constant *Pointer, unsigned Key, bool UseAddressDiscrimination,
llvm::ConstantInt *OtherDiscriminator) {
llvm::Constant *StorageAddress = nullptr;
if (UseAddressDiscrimination)
StorageAddress = getAddrOfCurrentPosition(Pointer->getType());

llvm::Constant *SignedPointer = Builder.CGM.getConstantSignedPointer(
Pointer, Key, StorageAddress, OtherDiscriminator);
add(SignedPointer);
}
16 changes: 16 additions & 0 deletions clang/test/CodeGenObjC/ptrauth-attr-exception.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// RUN: %clang_cc1 -triple arm64-apple-ios -fptrauth-calls -emit-llvm -fexceptions -fobjc-exceptions -o - %s | FileCheck %s

__attribute__((objc_root_class))
@interface Root {
Class isa;
}
@end

__attribute__((objc_exception))
@interface A : Root
@end

@implementation A
@end

// CHECK: @"OBJC_EHTYPE_$_A" = global {{%.*}} { ptr ptrauth (ptr getelementptr inbounds (ptr, ptr @objc_ehtype_vtable, i32 2), i32 2),
Loading