1 // RUN: %clang_cc1 -triple arm64-apple-ios -fptrauth-intrinsics -emit-llvm %s -o - | FileCheck %s
2 // RUN: %clang_cc1 -triple aarch64-elf -fptrauth-intrinsics -emit-llvm %s -o - | FileCheck %s
4 // RUN: %clang_cc1 -triple arm64-apple-ios -fptrauth-intrinsics -emit-llvm %s -o - -fexperimental-new-constant-interpreter | FileCheck %s
5 // RUN: %clang_cc1 -triple aarch64-elf -fptrauth-intrinsics -emit-llvm %s -o - -fexperimental-new-constant-interpreter | FileCheck %s
8 long int_discriminator
;
9 void *ptr_discriminator
;
12 // CHECK-LABEL: define {{.*}}void @test_auth()
14 // CHECK: [[PTR:%.*]] = load ptr, ptr @fnptr,
15 // CHECK-NEXT: [[DISC0:%.*]] = load ptr, ptr @ptr_discriminator,
16 // CHECK-NEXT: [[T0:%.*]] = ptrtoint ptr [[PTR]] to i64
17 // CHECK-NEXT: [[DISC:%.*]] = ptrtoint ptr [[DISC0]] to i64
18 // CHECK-NEXT: [[T1:%.*]] = call i64 @llvm.ptrauth.auth(i64 [[T0]], i32 0, i64 [[DISC]])
19 // CHECK-NEXT: [[RESULT:%.*]] = inttoptr i64 [[T1]] to ptr
20 // CHECK-NEXT: store ptr [[RESULT]], ptr @fnptr,
21 fnptr
= __builtin_ptrauth_auth(fnptr
, 0, ptr_discriminator
);
24 // CHECK-LABEL: define {{.*}}void @test_strip()
26 // CHECK: [[PTR:%.*]] = load ptr, ptr @fnptr,
27 // CHECK-NEXT: [[T0:%.*]] = ptrtoint ptr [[PTR]] to i64
28 // CHECK-NEXT: [[T1:%.*]] = call i64 @llvm.ptrauth.strip(i64 [[T0]], i32 0)
29 // CHECK-NEXT: [[RESULT:%.*]] = inttoptr i64 [[T1]] to ptr
30 // CHECK-NEXT: store ptr [[RESULT]], ptr @fnptr,
31 fnptr
= __builtin_ptrauth_strip(fnptr
, 0);
34 // CHECK-LABEL: define {{.*}}void @test_sign_unauthenticated()
35 void test_sign_unauthenticated() {
36 // CHECK: [[PTR:%.*]] = load ptr, ptr @fnptr,
37 // CHECK-NEXT: [[DISC0:%.*]] = load ptr, ptr @ptr_discriminator,
38 // CHECK-NEXT: [[T0:%.*]] = ptrtoint ptr [[PTR]] to i64
39 // CHECK-NEXT: [[DISC:%.*]] = ptrtoint ptr [[DISC0]] to i64
40 // CHECK-NEXT: [[T1:%.*]] = call i64 @llvm.ptrauth.sign(i64 [[T0]], i32 0, i64 [[DISC]])
41 // CHECK-NEXT: [[RESULT:%.*]] = inttoptr i64 [[T1]] to ptr
42 // CHECK-NEXT: store ptr [[RESULT]], ptr @fnptr,
43 fnptr
= __builtin_ptrauth_sign_unauthenticated(fnptr
, 0, ptr_discriminator
);
46 // CHECK-LABEL: define {{.*}}void @test_auth_and_resign()
47 void test_auth_and_resign() {
48 // CHECK: [[PTR:%.*]] = load ptr, ptr @fnptr,
49 // CHECK-NEXT: [[DISC0:%.*]] = load ptr, ptr @ptr_discriminator,
50 // CHECK-NEXT: [[T0:%.*]] = ptrtoint ptr [[PTR]] to i64
51 // CHECK-NEXT: [[DISC:%.*]] = ptrtoint ptr [[DISC0]] to i64
52 // CHECK-NEXT: [[T1:%.*]] = call i64 @llvm.ptrauth.resign(i64 [[T0]], i32 0, i64 [[DISC]], i32 3, i64 15)
53 // CHECK-NEXT: [[RESULT:%.*]] = inttoptr i64 [[T1]] to ptr
54 // CHECK-NEXT: store ptr [[RESULT]], ptr @fnptr,
55 fnptr
= __builtin_ptrauth_auth_and_resign(fnptr
, 0, ptr_discriminator
, 3, 15);
58 // CHECK-LABEL: define {{.*}}void @test_blend_discriminator()
59 void test_blend_discriminator() {
60 // CHECK: [[PTR:%.*]] = load ptr, ptr @fnptr,
61 // CHECK-NEXT: [[DISC:%.*]] = load i64, ptr @int_discriminator,
62 // CHECK-NEXT: [[T0:%.*]] = ptrtoint ptr [[PTR]] to i64
63 // CHECK-NEXT: [[RESULT:%.*]] = call i64 @llvm.ptrauth.blend(i64 [[T0]], i64 [[DISC]])
64 // CHECK-NEXT: store i64 [[RESULT]], ptr @int_discriminator,
65 int_discriminator
= __builtin_ptrauth_blend_discriminator(fnptr
, int_discriminator
);
68 // CHECK-LABEL: define {{.*}}void @test_sign_generic_data()
69 void test_sign_generic_data() {
70 // CHECK: [[PTR:%.*]] = load ptr, ptr @fnptr,
71 // CHECK-NEXT: [[DISC0:%.*]] = load ptr, ptr @ptr_discriminator,
72 // CHECK-NEXT: [[T0:%.*]] = ptrtoint ptr [[PTR]] to i64
73 // CHECK-NEXT: [[DISC:%.*]] = ptrtoint ptr [[DISC0]] to i64
74 // CHECK-NEXT: [[RESULT:%.*]] = call i64 @llvm.ptrauth.sign.generic(i64 [[T0]], i64 [[DISC]])
75 // CHECK-NEXT: store i64 [[RESULT]], ptr @signature,
76 signature
= __builtin_ptrauth_sign_generic_data(fnptr
, ptr_discriminator
);
79 // CHECK-LABEL: define {{.*}}void @test_string_discriminator()
80 void test_string_discriminator() {
81 // CHECK: [[X:%.*]] = alloca i32
83 // Check a couple of random discriminators used by Swift.
85 // CHECK: store i32 58298, ptr [[X]],
86 int x
= __builtin_ptrauth_string_discriminator("InitializeWithCopy");
88 // CHECK: store i32 9112, ptr [[X]],
89 x
= __builtin_ptrauth_string_discriminator("DestroyArray");