| 1 |
// RUN: %clang_cc1 -triple arm64-apple-ios -fblocks -fptrauth-calls -fptrauth-returns -fptrauth-intrinsics -emit-llvm -o - %s | FileCheck %s |
| 2 |
|
| 3 |
#define AQ1_50 __ptrauth(1,1,50) |
| 4 |
#define AQ2_30 __ptrauth(2,1,30) |
| 5 |
#define IQ __ptrauth(1,0,50) |
| 6 |
|
| 7 |
typedef void (^BlockTy)(void); |
| 8 |
|
| 9 |
// CHECK: %[[STRUCT_SA:.*]] = type { i32, ptr } |
| 10 |
// CHECK: %[[STRUCT_SA2:.*]] = type { i32, ptr } |
| 11 |
// CHECK: %[[STRUCT_SI:.*]] = type { ptr } |
| 12 |
|
| 13 |
typedef struct { |
| 14 |
int f0; |
| 15 |
int * AQ1_50 f1; // Signed using address discrimination. |
| 16 |
} SA; |
| 17 |
|
| 18 |
typedef struct { |
| 19 |
int f0; |
| 20 |
int * AQ2_30 f1; // Signed using address discrimination. |
| 21 |
} SA2; |
| 22 |
|
| 23 |
typedef struct { |
| 24 |
int * IQ f; // No address discrimination. |
| 25 |
} SI; |
| 26 |
|
| 27 |
typedef struct { |
| 28 |
// Transitively includes an address discriminated value |
| 29 |
SA nested; |
| 30 |
} Nested_AddrDiscrimination; |
| 31 |
|
| 32 |
typedef struct { |
| 33 |
// Transitively includes a pointer to a struct containing |
| 34 |
// an address discriminated value, which means that this |
| 35 |
// does not actually contain an address discriminated value |
| 36 |
SA *nestedPtr; |
| 37 |
} Nested_PtrAddrDiscrimination; |
| 38 |
|
| 39 |
SA getSA(void); |
| 40 |
void calleeSA(SA); |
| 41 |
|
| 42 |
int g0; |
| 43 |
|
| 44 |
// CHECK: define void @test_copy_constructor_SA(ptr noundef %{{.*}}) |
| 45 |
// CHECK: call void @__copy_constructor_8_8_t0w4_pa1_50_8( |
| 46 |
|
| 47 |
// CHECK: define linkonce_odr hidden void @__copy_constructor_8_8_t0w4_pa1_50_8(ptr noundef %[[DST:.*]], ptr noundef %[[SRC:.*]]) |
| 48 |
// CHECK: %[[DST_ADDR:.*]] = alloca ptr, align 8 |
| 49 |
// CHECK: %[[SRC_ADDR:.*]] = alloca ptr, align 8 |
| 50 |
// CHECK: store ptr %[[DST]], ptr %[[DST_ADDR]], align 8 |
| 51 |
// CHECK: store ptr %[[SRC]], ptr %[[SRC_ADDR]], align 8 |
| 52 |
// CHECK: %[[V0:.*]] = load ptr, ptr %[[DST_ADDR]], align 8 |
| 53 |
// CHECK: %[[V1:.*]] = load ptr, ptr %[[SRC_ADDR]], align 8 |
| 54 |
// CHECK: %[[V6:.*]] = getelementptr inbounds i8, ptr %[[V0]], i64 8 |
| 55 |
// CHECK: %[[V9:.*]] = getelementptr inbounds i8, ptr %[[V1]], i64 8 |
| 56 |
// CHECK: %[[V11:.*]] = load ptr, ptr %[[V9]], align 8 |
| 57 |
// CHECK: %[[V12:.*]] = ptrtoint ptr %[[V9]] to i64 |
| 58 |
// CHECK: %[[V13:.*]] = call i64 @llvm.ptrauth.blend(i64 %[[V12]], i64 50) |
| 59 |
// CHECK: %[[V14:.*]] = ptrtoint ptr %[[V6]] to i64 |
| 60 |
// CHECK: %[[V15:.*]] = call i64 @llvm.ptrauth.blend(i64 %[[V14]], i64 50) |
| 61 |
// CHECK: %[[V17:.*]] = ptrtoint ptr %[[V11]] to i64 |
| 62 |
// CHECK: %[[V18:.*]] = call i64 @llvm.ptrauth.resign(i64 %[[V17]], i32 1, i64 %[[V13]], i32 1, i64 %[[V15]]) |
| 63 |
|
| 64 |
void test_copy_constructor_SA(SA *s) { |
| 65 |
SA t = *s; |
| 66 |
} |
| 67 |
|
| 68 |
// CHECK: define void @test_copy_constructor_SA2(ptr noundef %{{.*}}) |
| 69 |
// CHECK: call void @__copy_constructor_8_8_t0w4_pa2_30_8( |
| 70 |
|
| 71 |
// CHECK: define linkonce_odr hidden void @__copy_constructor_8_8_t0w4_pa2_30_8(ptr noundef %[[DST:.*]], ptr noundef %[[SRC:.*]]) |
| 72 |
// CHECK: %[[DST_ADDR:.*]] = alloca ptr, align 8 |
| 73 |
// CHECK: %[[SRC_ADDR:.*]] = alloca ptr, align 8 |
| 74 |
// CHECK: store ptr %[[DST]], ptr %[[DST_ADDR]], align 8 |
| 75 |
// CHECK: store ptr %[[SRC]], ptr %[[SRC_ADDR]], align 8 |
| 76 |
// CHECK: %[[V0:.*]] = load ptr, ptr %[[DST_ADDR]], align 8 |
| 77 |
// CHECK: %[[V1:.*]] = load ptr, ptr %[[SRC_ADDR]], align 8 |
| 78 |
// CHECK: %[[V6:.*]] = getelementptr inbounds i8, ptr %[[V0]], i64 8 |
| 79 |
// CHECK: %[[V9:.*]] = getelementptr inbounds i8, ptr %[[V1]], i64 8 |
| 80 |
// CHECK: %[[V11:.*]] = load ptr, ptr %[[V9]], align 8 |
| 81 |
// CHECK: %[[V12:.*]] = ptrtoint ptr %[[V9]] to i64 |
| 82 |
// CHECK: %[[V13:.*]] = call i64 @llvm.ptrauth.blend(i64 %[[V12]], i64 30) |
| 83 |
// CHECK: %[[V14:.*]] = ptrtoint ptr %[[V6]] to i64 |
| 84 |
// CHECK: %[[V15:.*]] = call i64 @llvm.ptrauth.blend(i64 %[[V14]], i64 30) |
| 85 |
// CHECK: %[[V17:.*]] = ptrtoint ptr %[[V11]] to i64 |
| 86 |
// CHECK: %[[V18:.*]] = call i64 @llvm.ptrauth.resign(i64 %[[V17]], i32 2, i64 %[[V13]], i32 2, i64 %[[V15]]) |
| 87 |
|
| 88 |
void test_copy_constructor_SA2(SA2 *s) { |
| 89 |
SA2 t = *s; |
| 90 |
} |
| 91 |
|
| 92 |
// CHECK: define void @test_copy_assignment_SA( |
| 93 |
// CHECK: call void @__copy_assignment_8_8_t0w4_pa1_50_8( |
| 94 |
|
| 95 |
// CHECK: define linkonce_odr hidden void @__copy_assignment_8_8_t0w4_pa1_50_8( |
| 96 |
|
| 97 |
void test_copy_assignment_SA(SA *d, SA *s) { |
| 98 |
*d = *s; |
| 99 |
} |
| 100 |
|
| 101 |
// CHECK: define void @test_move_constructor_SA( |
| 102 |
// CHECK: define internal void @__Block_byref_object_copy_( |
| 103 |
// CHECK: define linkonce_odr hidden void @__move_constructor_8_8_t0w4_pa1_50_8( |
| 104 |
|
| 105 |
void test_move_constructor_SA(void) { |
| 106 |
__block SA t; |
| 107 |
BlockTy b = ^{ (void)t; }; |
| 108 |
} |
| 109 |
|
| 110 |
// CHECK: define void @test_move_assignment_SA( |
| 111 |
// CHECK: call void @__move_assignment_8_8_t0w4_pa1_50_8( |
| 112 |
// CHECK: define linkonce_odr hidden void @__move_assignment_8_8_t0w4_pa1_50_8( |
| 113 |
|
| 114 |
void test_move_assignment_SA(SA *p) { |
| 115 |
*p = getSA(); |
| 116 |
} |
| 117 |
|
| 118 |
// CHECK: define void @test_parameter_SA(ptr dead_on_return noundef %{{.*}}) |
| 119 |
// CHECK-NOT: call |
| 120 |
// CHECK: ret void |
| 121 |
|
| 122 |
void test_parameter_SA(SA a) { |
| 123 |
} |
| 124 |
|
| 125 |
// CHECK: define void @test_argument_SA(ptr noundef %[[A:.*]]) |
| 126 |
// CHECK: %[[A_ADDR:.*]] = alloca ptr, align 8 |
| 127 |
// CHECK: %[[AGG_TMP:.*]] = alloca %[[STRUCT_SA]], align 8 |
| 128 |
// CHECK: store ptr %[[A]], ptr %[[A_ADDR]], align 8 |
| 129 |
// CHECK: %[[V0:.*]] = load ptr, ptr %[[A_ADDR]], align 8 |
| 130 |
// CHECK: call void @__copy_constructor_8_8_t0w4_pa1_50_8(ptr %[[AGG_TMP]], ptr %[[V0]]) |
| 131 |
// CHECK: call void @calleeSA(ptr dead_on_return noundef %[[AGG_TMP]]) |
| 132 |
// CHECK-NOT: call |
| 133 |
// CHECK: ret void |
| 134 |
|
| 135 |
void test_argument_SA(SA *a) { |
| 136 |
calleeSA(*a); |
| 137 |
} |
| 138 |
|
| 139 |
// CHECK: define void @test_return_SA(ptr dead_on_unwind noalias writable sret(%struct.SA) align 8 %[[AGG_RESULT:.*]], ptr noundef %[[A:.*]]) |
| 140 |
// CHECK: %[[A_ADDR:.*]] = alloca ptr, align 8 |
| 141 |
// CHECK: store ptr %[[A]], ptr %[[A_ADDR]], align 8 |
| 142 |
// CHECK: %[[V0:.*]] = load ptr, ptr %[[A_ADDR]], align 8 |
| 143 |
// CHECK: call void @__copy_constructor_8_8_t0w4_pa1_50_8(ptr %[[AGG_RESULT]], ptr %[[V0]]) |
| 144 |
// CHECK-NOT: call |
| 145 |
// CHECK: ret void |
| 146 |
|
| 147 |
SA test_return_SA(SA *a) { |
| 148 |
return *a; |
| 149 |
} |
| 150 |
|
| 151 |
// CHECK: define void @test_copy_constructor_SI( |
| 152 |
// CHECK-NOT: call |
| 153 |
// CHECK: call void @llvm.memcpy.p0.p0.i64( |
| 154 |
// CHECK-NOT: call |
| 155 |
// CHECK: ret void |
| 156 |
|
| 157 |
void test_copy_constructor_SI(SI *s) { |
| 158 |
SI t = *s; |
| 159 |
} |
| 160 |
|
| 161 |
// CHECK: define void @test_parameter_SI(ptr %{{.*}}) |
| 162 |
// CHECK-NOT: call |
| 163 |
// CHECK: ret void |
| 164 |
|
| 165 |
void test_parameter_SI(SI a) { |
| 166 |
} |
| 167 |
|
| 168 |
// CHECK-LABEL: define void @test_array( |
| 169 |
// CHECK: %[[F1:.*]] = getelementptr inbounds nuw %[[STRUCT_SA]], ptr %{{.*}}, i32 0, i32 1 |
| 170 |
// CHECK: %[[V0:.*]] = ptrtoint ptr %[[F1]] to i64 |
| 171 |
// CHECK: %[[V1:.*]] = call i64 @llvm.ptrauth.blend(i64 %[[V0]], i64 50) |
| 172 |
// CHECK: %[[V2:.*]] = call i64 @llvm.ptrauth.sign(i64 ptrtoint (ptr @g0 to i64), i32 1, i64 %[[V1]]) |
| 173 |
// CHECK: %[[V3:.*]] = inttoptr i64 %[[V2]] to ptr |
| 174 |
// CHECK: store ptr %[[V3]], ptr %[[F1]], align 8 |
| 175 |
// CHECK: %[[F12:.*]] = getelementptr inbounds nuw %[[STRUCT_SA]], ptr %{{.*}}, i32 0, i32 1 |
| 176 |
// CHECK: %[[V4:.*]] = ptrtoint ptr %[[F12]] to i64 |
| 177 |
// CHECK: %[[V5:.*]] = call i64 @llvm.ptrauth.blend(i64 %[[V4]], i64 50) |
| 178 |
// CHECK: %[[V6:.*]] = call i64 @llvm.ptrauth.sign(i64 ptrtoint (ptr @g0 to i64), i32 1, i64 %[[V5]]) |
| 179 |
// CHECK: %[[V7:.*]] = inttoptr i64 %[[V6]] to ptr |
| 180 |
// CHECK: store ptr %[[V7]], ptr %[[F12]], align 8 |
| 181 |
|
| 182 |
void test_array(void) { |
| 183 |
const SA a[] = {{0, &g0}, {1, &g0}}; |
| 184 |
} |
| 185 |
|
| 186 |
|
| 187 |
void test_nested_struct(Nested_AddrDiscrimination* Src) { |
| 188 |
Nested_AddrDiscrimination Dst = *Src; |
| 189 |
} |
| 190 |
// CHECK-LABEL: define void @test_nested_struct |
| 191 |
// CHECK: [[DST:%.*]] = alloca %struct.Nested_AddrDiscrimination |
| 192 |
// CHECK: [[SRC_ADDR:%.*]] = load ptr, ptr %Src.addr |
| 193 |
// CHECK: call void @__copy_constructor_8_8_S_t0w4_pa1_50_8(ptr [[DST]], ptr [[SRC_ADDR]]) |
| 194 |
|
| 195 |
// CHECK-LABEL: define linkonce_odr hidden void @__copy_constructor_8_8_S_t0w4_pa1_50_8( |
| 196 |
// CHECK: call void @__copy_constructor_8_8_t0w4_pa1_50_8 |
| 197 |
|
| 198 |
|
| 199 |
void test_nested_struct_ptr(Nested_PtrAddrDiscrimination* Src) { |
| 200 |
Nested_PtrAddrDiscrimination Dst = *Src; |
| 201 |
} |
| 202 |
// CHECK-LABEL: define void @test_nested_struct_ptr |
| 203 |
// CHECK: [[DST:%.*]] = alloca %struct.Nested_PtrAddrDiscrimination |
| 204 |
// CHECK: [[SRC_ADDR:%.*]] = load ptr, ptr %Src.addr |
| 205 |
// CHECK: call void @llvm.memcpy.p0.p0.i64(ptr align 8 [[DST]], ptr align 8 [[SRC_ADDR]], i64 8, i1 false) |