|
1 | 1 | ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py |
2 | 2 | ; RUN: opt < %s -passes=instcombine -S | FileCheck %s |
3 | 3 |
|
4 | | -define i32 @test_ptrauth_call_resign(ptr %p) { |
5 | | -; CHECK-LABEL: @test_ptrauth_call_resign( |
6 | | -; CHECK-NEXT: [[TMP3:%.*]] = call i32 [[P:%.*]]() [ "ptrauth"(i32 0, i64 1234) ] |
7 | | -; CHECK-NEXT: ret i32 [[TMP3]] |
| 4 | +declare i64 @f(i32) |
| 5 | +declare ptr @f2(i32) |
| 6 | + |
| 7 | +define i32 @test_ptrauth_call(i32 %a0) { |
| 8 | +; CHECK-LABEL: @test_ptrauth_call( |
| 9 | +; CHECK-NEXT: [[V0:%.*]] = call i32 @f(i32 [[A0:%.*]]) |
| 10 | +; CHECK-NEXT: ret i32 [[V0]] |
| 11 | +; |
| 12 | + %v0 = call i32 ptrauth(ptr @f, i32 0)(i32 %a0) [ "ptrauth"(i32 0, i64 0) ] |
| 13 | + ret i32 %v0 |
| 14 | +} |
| 15 | + |
| 16 | +define i32 @test_ptrauth_call_disc(i32 %a0) { |
| 17 | +; CHECK-LABEL: @test_ptrauth_call_disc( |
| 18 | +; CHECK-NEXT: [[V0:%.*]] = call i32 @f(i32 [[A0:%.*]]) |
| 19 | +; CHECK-NEXT: ret i32 [[V0]] |
| 20 | +; |
| 21 | + %v0 = call i32 ptrauth(ptr @f, i32 1, i64 5678)(i32 %a0) [ "ptrauth"(i32 1, i64 5678) ] |
| 22 | + ret i32 %v0 |
| 23 | +} |
| 24 | + |
| 25 | +@f_addr_disc.ref = constant ptr ptrauth(ptr @f, i32 1, i64 0, ptr @f_addr_disc.ref) |
| 26 | + |
| 27 | +define i32 @test_ptrauth_call_addr_disc(i32 %a0) { |
| 28 | +; CHECK-LABEL: @test_ptrauth_call_addr_disc( |
| 29 | +; CHECK-NEXT: [[V0:%.*]] = call i32 @f(i32 [[A0:%.*]]) |
| 30 | +; CHECK-NEXT: ret i32 [[V0]] |
| 31 | +; |
| 32 | + %v0 = call i32 ptrauth(ptr @f, i32 1, i64 0, ptr @f_addr_disc.ref)(i32 %a0) [ "ptrauth"(i32 1, i64 ptrtoint (ptr @f_addr_disc.ref to i64)) ] |
| 33 | + ret i32 %v0 |
| 34 | +} |
| 35 | + |
| 36 | +@f_both_disc.ref = constant ptr ptrauth(ptr @f, i32 1, i64 1234, ptr @f_both_disc.ref) |
| 37 | + |
| 38 | +define i32 @test_ptrauth_call_blend(i32 %a0) { |
| 39 | +; CHECK-LABEL: @test_ptrauth_call_blend( |
| 40 | +; CHECK-NEXT: [[V0:%.*]] = call i32 @f(i32 [[A0:%.*]]) |
| 41 | +; CHECK-NEXT: ret i32 [[V0]] |
| 42 | +; |
| 43 | + %v = call i64 @llvm.ptrauth.blend(i64 ptrtoint (ptr @f_both_disc.ref to i64), i64 1234) |
| 44 | + %v0 = call i32 ptrauth(ptr @f, i32 1, i64 1234, ptr @f_both_disc.ref)(i32 %a0) [ "ptrauth"(i32 1, i64 %v) ] |
| 45 | + ret i32 %v0 |
| 46 | +} |
| 47 | + |
| 48 | +define i64 @test_ptrauth_call_cast(i32 %a0) { |
| 49 | +; CHECK-LABEL: @test_ptrauth_call_cast( |
| 50 | +; CHECK-NEXT: [[V0:%.*]] = call i64 @f2(i32 [[A0:%.*]]) |
| 51 | +; CHECK-NEXT: ret i64 [[V0]] |
8 | 52 | ; |
9 | | - %tmp0 = ptrtoint ptr %p to i64 |
10 | | - %tmp1 = call i64 @llvm.ptrauth.resign(i64 %tmp0, i32 0, i64 1234, i32 2, i64 5678) |
11 | | - %tmp2 = inttoptr i64 %tmp1 to ptr |
12 | | - %tmp3 = call i32 %tmp2() [ "ptrauth"(i32 2, i64 5678) ] |
13 | | - ret i32 %tmp3 |
| 53 | + %v0 = call i64 ptrauth(ptr @f2, i32 0)(i32 %a0) [ "ptrauth"(i32 0, i64 0) ] |
| 54 | + ret i64 %v0 |
14 | 55 | } |
15 | 56 |
|
16 | | -define i32 @test_ptrauth_call_resign_blend(ptr %pp) { |
17 | | -; CHECK-LABEL: @test_ptrauth_call_resign_blend( |
18 | | -; CHECK-NEXT: [[TMP01:%.*]] = load ptr, ptr [[PP:%.*]], align 8 |
19 | | -; CHECK-NEXT: [[TMP6:%.*]] = call i32 [[TMP01]]() [ "ptrauth"(i32 0, i64 1234) ] |
20 | | -; CHECK-NEXT: ret i32 [[TMP6]] |
| 57 | +define i32 @test_ptrauth_call_mismatch_key(i32 %a0) { |
| 58 | +; CHECK-LABEL: @test_ptrauth_call_mismatch_key( |
| 59 | +; CHECK-NEXT: [[V0:%.*]] = call i32 ptrauth (ptr @f, i32 1, i64 5678)(i32 [[A0:%.*]]) [ "ptrauth"(i32 0, i64 5678) ] |
| 60 | +; CHECK-NEXT: ret i32 [[V0]] |
21 | 61 | ; |
22 | | - %tmp0 = load ptr, ptr %pp, align 8 |
23 | | - %tmp1 = ptrtoint ptr %pp to i64 |
24 | | - %tmp2 = ptrtoint ptr %tmp0 to i64 |
25 | | - %tmp3 = call i64 @llvm.ptrauth.blend(i64 %tmp1, i64 5678) |
26 | | - %tmp4 = call i64 @llvm.ptrauth.resign(i64 %tmp2, i32 0, i64 1234, i32 1, i64 %tmp3) |
27 | | - %tmp5 = inttoptr i64 %tmp4 to ptr |
28 | | - %tmp6 = call i32 %tmp5() [ "ptrauth"(i32 1, i64 %tmp3) ] |
29 | | - ret i32 %tmp6 |
| 62 | + %v0 = call i32 ptrauth(ptr @f, i32 1, i64 5678)(i32 %a0) [ "ptrauth"(i32 0, i64 5678) ] |
| 63 | + ret i32 %v0 |
30 | 64 | } |
31 | 65 |
|
32 | | -define i32 @test_ptrauth_call_resign_blend_2(ptr %pp) { |
33 | | -; CHECK-LABEL: @test_ptrauth_call_resign_blend_2( |
34 | | -; CHECK-NEXT: [[TMP01:%.*]] = load ptr, ptr [[PP:%.*]], align 8 |
35 | | -; CHECK-NEXT: [[TMP1:%.*]] = ptrtoint ptr [[PP]] to i64 |
36 | | -; CHECK-NEXT: [[TMP3:%.*]] = call i64 @llvm.ptrauth.blend(i64 [[TMP1]], i64 5678) |
37 | | -; CHECK-NEXT: [[TMP6:%.*]] = call i32 [[TMP01]]() [ "ptrauth"(i32 1, i64 [[TMP3]]) ] |
38 | | -; CHECK-NEXT: ret i32 [[TMP6]] |
| 66 | +define i32 @test_ptrauth_call_mismatch_disc(i32 %a0) { |
| 67 | +; CHECK-LABEL: @test_ptrauth_call_mismatch_disc( |
| 68 | +; CHECK-NEXT: [[V0:%.*]] = call i32 ptrauth (ptr @f, i32 1, i64 5678)(i32 [[A0:%.*]]) [ "ptrauth"(i32 1, i64 0) ] |
| 69 | +; CHECK-NEXT: ret i32 [[V0]] |
39 | 70 | ; |
40 | | - %tmp0 = load ptr, ptr %pp, align 8 |
41 | | - %tmp1 = ptrtoint ptr %pp to i64 |
42 | | - %tmp2 = ptrtoint ptr %tmp0 to i64 |
43 | | - %tmp3 = call i64 @llvm.ptrauth.blend(i64 %tmp1, i64 5678) |
44 | | - %tmp4 = call i64 @llvm.ptrauth.resign(i64 %tmp2, i32 1, i64 %tmp3, i32 0, i64 1234) |
45 | | - %tmp5 = inttoptr i64 %tmp4 to ptr |
46 | | - %tmp6 = call i32 %tmp5() [ "ptrauth"(i32 0, i64 1234) ] |
47 | | - ret i32 %tmp6 |
| 71 | + %v0 = call i32 ptrauth(ptr @f, i32 1, i64 5678)(i32 %a0) [ "ptrauth"(i32 1, i64 0) ] |
| 72 | + ret i32 %v0 |
48 | 73 | } |
49 | 74 |
|
50 | | -define i32 @test_ptrauth_call_auth(ptr %p) { |
51 | | -; CHECK-LABEL: @test_ptrauth_call_auth( |
52 | | -; CHECK-NEXT: [[TMP3:%.*]] = call i32 [[P:%.*]]() [ "ptrauth"(i32 2, i64 5678) ] |
53 | | -; CHECK-NEXT: ret i32 [[TMP3]] |
| 75 | +define i32 @test_ptrauth_call_mismatch_blend(i32 %a0) { |
| 76 | +; CHECK-LABEL: @test_ptrauth_call_mismatch_blend( |
| 77 | +; CHECK-NEXT: [[V:%.*]] = call i64 @llvm.ptrauth.blend(i64 ptrtoint (ptr @f_both_disc.ref to i64), i64 0) |
| 78 | +; CHECK-NEXT: [[V0:%.*]] = call i32 ptrauth (ptr @f, i32 1, i64 1234, ptr @f_both_disc.ref)(i32 [[A0:%.*]]) [ "ptrauth"(i32 1, i64 [[V]]) ] |
| 79 | +; CHECK-NEXT: ret i32 [[V0]] |
54 | 80 | ; |
55 | | - %tmp0 = ptrtoint ptr %p to i64 |
56 | | - %tmp1 = call i64 @llvm.ptrauth.auth(i64 %tmp0, i32 2, i64 5678) |
57 | | - %tmp2 = inttoptr i64 %tmp1 to ptr |
58 | | - %tmp3 = call i32 %tmp2() |
59 | | - ret i32 %tmp3 |
| 81 | + %v = call i64 @llvm.ptrauth.blend(i64 ptrtoint (ptr @f_both_disc.ref to i64), i64 0) |
| 82 | + %v0 = call i32 ptrauth(ptr @f, i32 1, i64 1234, ptr @f_both_disc.ref)(i32 %a0) [ "ptrauth"(i32 1, i64 %v) ] |
| 83 | + ret i32 %v0 |
60 | 84 | } |
61 | 85 |
|
62 | | -define i32 @test_ptrauth_call_sign(ptr %p) { |
63 | | -; CHECK-LABEL: @test_ptrauth_call_sign( |
64 | | -; CHECK-NEXT: [[TMP3:%.*]] = call i32 [[P:%.*]]() |
65 | | -; CHECK-NEXT: ret i32 [[TMP3]] |
| 86 | +define i32 @test_ptrauth_call_mismatch_blend_addr(i32 %a0) { |
| 87 | +; CHECK-LABEL: @test_ptrauth_call_mismatch_blend_addr( |
| 88 | +; CHECK-NEXT: [[V:%.*]] = call i64 @llvm.ptrauth.blend(i64 ptrtoint (ptr @f_addr_disc.ref to i64), i64 1234) |
| 89 | +; CHECK-NEXT: [[V0:%.*]] = call i32 ptrauth (ptr @f, i32 1, i64 1234, ptr @f_both_disc.ref)(i32 [[A0:%.*]]) [ "ptrauth"(i32 1, i64 [[V]]) ] |
| 90 | +; CHECK-NEXT: ret i32 [[V0]] |
66 | 91 | ; |
67 | | - %tmp0 = ptrtoint ptr %p to i64 |
68 | | - %tmp1 = call i64 @llvm.ptrauth.sign(i64 %tmp0, i32 2, i64 5678) |
69 | | - %tmp2 = inttoptr i64 %tmp1 to ptr |
70 | | - %tmp3 = call i32 %tmp2() [ "ptrauth"(i32 2, i64 5678) ] |
71 | | - ret i32 %tmp3 |
| 92 | + %v = call i64 @llvm.ptrauth.blend(i64 ptrtoint (ptr @f_addr_disc.ref to i64), i64 1234) |
| 93 | + %v0 = call i32 ptrauth(ptr @f, i32 1, i64 1234, ptr @f_both_disc.ref)(i32 %a0) [ "ptrauth"(i32 1, i64 %v) ] |
| 94 | + ret i32 %v0 |
72 | 95 | } |
73 | 96 |
|
74 | | -declare i64 @llvm.ptrauth.auth(i64, i32, i64) |
75 | | -declare i64 @llvm.ptrauth.sign(i64, i32, i64) |
76 | | -declare i64 @llvm.ptrauth.resign(i64, i32, i64, i32, i64) |
77 | 97 | declare i64 @llvm.ptrauth.blend(i64, i64) |
0 commit comments