llvm-project/clang/test/SemaObjC/ptrauth-pointers.m
Oliver Hunt 451a9ce9ff
[clang][ObjC][PAC] Add ptrauth protections to objective-c (#147899)
This PR introduces the use of pointer authentication to objective-c[++].

This includes:

* __ptrauth qualifier support for ivars
* protection of isa and super fields
* protection of SEL typed ivars
* protection of class_ro_t data
* protection of methodlist pointers and content
2025-07-14 19:32:18 -07:00

47 lines
2.1 KiB
Objective-C

// RUN: %clang_cc1 -fblocks -triple arm64-apple-ios -fptrauth-calls -fptrauth-intrinsics -verify %s
#if __has_feature(ptrauth_objc_signable_class)
@class TestClass;
typedef TestClass *ClassPtr;
typedef void(^BlockPtr)();
@interface TestClass {
@public
__ptrauth(2, 1, 1) Class a;
__ptrauth(2, 1, 3) volatile Class vi;
__ptrauth(2, 1, 3) const Class ci;
__ptrauth(2, 1, 1) id b;
// expected-error@-1 {{'__ptrauth' qualifier only applies to pointer or pointer sized integer types; 'id' is invalid}}
__ptrauth(2, 1, 2) ClassPtr c;
// expected-error@-1 {{'__ptrauth' qualifier only applies to pointer or pointer sized integer types; 'ClassPtr' (aka 'TestClass *') is invalid}}
__ptrauth(2, 1, 2) BlockPtr d;
// expected-error@-1 {{'__ptrauth' qualifier only applies to pointer or pointer sized integer types; 'BlockPtr' (aka 'void (^)()') is invalid}}
}
struct TestStruct {
__ptrauth(2, 1, 3) Class e;
__ptrauth(2, 1, 3) volatile Class vi;
__ptrauth(2, 1, 3) const Class ci;
__ptrauth(2, 1, 4) id f;
// expected-error@-1 {{'__ptrauth' qualifier only applies to pointer or pointer sized integer types; 'id' is invalid}}
__ptrauth(2, 1, 5) ClassPtr g;
// expected-error@-1 {{'__ptrauth' qualifier only applies to pointer or pointer sized integer types; 'ClassPtr' (aka 'TestClass *') is invalid}}
__ptrauth(2, 1, 2) BlockPtr h;
// expected-error@-1 {{'__ptrauth' qualifier only applies to pointer or pointer sized integer types; 'BlockPtr' (aka 'void (^)()') is invalid}}
};
@end
void foo() {
__ptrauth(2, 1, 3) Class i;
__ptrauth(2, 1, 3) volatile Class vi;
__ptrauth(2, 1, 3) const Class ci = 0;
__ptrauth(2, 1, 4) id j;
// expected-error@-1 {{'__ptrauth' qualifier only applies to pointer or pointer sized integer types; 'id' is invalid}}
__ptrauth(2, 1, 5) ClassPtr k;
// expected-error@-1 {{'__ptrauth' qualifier only applies to pointer or pointer sized integer types; 'ClassPtr' (aka 'TestClass *') is invalid}}
__ptrauth(2, 1, 2) BlockPtr l;
// expected-error@-1 {{'__ptrauth' qualifier only applies to pointer or pointer sized integer types; 'BlockPtr' (aka 'void (^)()') is invalid}}
}
#endif