|
| 1 | +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py |
| 2 | +; RUN: opt < %s -passes=instcombine -S | FileCheck %s |
| 3 | + |
| 4 | +target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128" |
| 5 | + |
| 6 | +declare i64 @f(i32) |
| 7 | +declare ptr @f2(i32) |
| 8 | + |
| 9 | +define i32 @test_ptrauth_call(i32 %a0) { |
| 10 | +; CHECK-LABEL: @test_ptrauth_call( |
| 11 | +; CHECK-NEXT: [[V0:%.*]] = call i32 @f(i32 [[A0:%.*]]) |
| 12 | +; CHECK-NEXT: ret i32 [[V0]] |
| 13 | +; |
| 14 | + %v0 = call i32 ptrauth(ptr @f, i32 0)(i32 %a0) [ "ptrauth"(i32 0, i64 0) ] |
| 15 | + ret i32 %v0 |
| 16 | +} |
| 17 | + |
| 18 | +define i32 @test_ptrauth_call_disc(i32 %a0) { |
| 19 | +; CHECK-LABEL: @test_ptrauth_call_disc( |
| 20 | +; CHECK-NEXT: [[V0:%.*]] = call i32 @f(i32 [[A0:%.*]]) |
| 21 | +; CHECK-NEXT: ret i32 [[V0]] |
| 22 | +; |
| 23 | + %v0 = call i32 ptrauth(ptr @f, i32 1, i64 5678)(i32 %a0) [ "ptrauth"(i32 1, i64 5678) ] |
| 24 | + ret i32 %v0 |
| 25 | +} |
| 26 | + |
| 27 | +@f_addr_disc.ref = constant ptr ptrauth(ptr @f, i32 1, i64 0, ptr @f_addr_disc.ref) |
| 28 | + |
| 29 | +define i32 @test_ptrauth_call_addr_disc(i32 %a0) { |
| 30 | +; CHECK-LABEL: @test_ptrauth_call_addr_disc( |
| 31 | +; CHECK-NEXT: [[V0:%.*]] = call i32 @f(i32 [[A0:%.*]]) |
| 32 | +; CHECK-NEXT: ret i32 [[V0]] |
| 33 | +; |
| 34 | + %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)) ] |
| 35 | + ret i32 %v0 |
| 36 | +} |
| 37 | + |
| 38 | +@f_both_disc.ref = constant ptr ptrauth(ptr @f, i32 1, i64 1234, ptr @f_both_disc.ref) |
| 39 | + |
| 40 | +define i32 @test_ptrauth_call_blend(i32 %a0) { |
| 41 | +; CHECK-LABEL: @test_ptrauth_call_blend( |
| 42 | +; CHECK-NEXT: [[V0:%.*]] = call i32 @f(i32 [[A0:%.*]]) |
| 43 | +; CHECK-NEXT: ret i32 [[V0]] |
| 44 | +; |
| 45 | + %v = call i64 @llvm.ptrauth.blend(i64 ptrtoint (ptr @f_both_disc.ref to i64), i64 1234) |
| 46 | + %v0 = call i32 ptrauth(ptr @f, i32 1, i64 1234, ptr @f_both_disc.ref)(i32 %a0) [ "ptrauth"(i32 1, i64 %v) ] |
| 47 | + ret i32 %v0 |
| 48 | +} |
| 49 | + |
| 50 | +define i64 @test_ptrauth_call_cast(i32 %a0) { |
| 51 | +; CHECK-LABEL: @test_ptrauth_call_cast( |
| 52 | +; CHECK-NEXT: [[V0:%.*]] = call ptr @f2(i32 [[A0:%.*]]) |
| 53 | +; CHECK-NEXT: [[TMP1:%.*]] = ptrtoint ptr [[V0]] to i64 |
| 54 | +; CHECK-NEXT: ret i64 [[TMP1]] |
| 55 | +; |
| 56 | + %v0 = call i64 ptrauth(ptr @f2, i32 0)(i32 %a0) [ "ptrauth"(i32 0, i64 0) ] |
| 57 | + ret i64 %v0 |
| 58 | +} |
| 59 | + |
| 60 | +define i32 @test_ptrauth_call_mismatch_key(i32 %a0) { |
| 61 | +; CHECK-LABEL: @test_ptrauth_call_mismatch_key( |
| 62 | +; CHECK-NEXT: [[V0:%.*]] = call i32 ptrauth (ptr @f, i32 1, i64 5678)(i32 [[A0:%.*]]) [ "ptrauth"(i32 0, i64 5678) ] |
| 63 | +; CHECK-NEXT: ret i32 [[V0]] |
| 64 | +; |
| 65 | + %v0 = call i32 ptrauth(ptr @f, i32 1, i64 5678)(i32 %a0) [ "ptrauth"(i32 0, i64 5678) ] |
| 66 | + ret i32 %v0 |
| 67 | +} |
| 68 | + |
| 69 | +define i32 @test_ptrauth_call_mismatch_disc(i32 %a0) { |
| 70 | +; CHECK-LABEL: @test_ptrauth_call_mismatch_disc( |
| 71 | +; CHECK-NEXT: [[V0:%.*]] = call i32 ptrauth (ptr @f, i32 1, i64 5678)(i32 [[A0:%.*]]) [ "ptrauth"(i32 1, i64 0) ] |
| 72 | +; CHECK-NEXT: ret i32 [[V0]] |
| 73 | +; |
| 74 | + %v0 = call i32 ptrauth(ptr @f, i32 1, i64 5678)(i32 %a0) [ "ptrauth"(i32 1, i64 0) ] |
| 75 | + ret i32 %v0 |
| 76 | +} |
| 77 | + |
| 78 | +define i32 @test_ptrauth_call_mismatch_blend(i32 %a0) { |
| 79 | +; CHECK-LABEL: @test_ptrauth_call_mismatch_blend( |
| 80 | +; CHECK-NEXT: [[V:%.*]] = call i64 @llvm.ptrauth.blend(i64 ptrtoint (ptr @f_both_disc.ref to i64), i64 0) |
| 81 | +; CHECK-NEXT: [[V0:%.*]] = call i32 ptrauth (ptr @f, i32 1, i64 1234, ptr @f_both_disc.ref)(i32 [[A0:%.*]]) [ "ptrauth"(i32 1, i64 [[V]]) ] |
| 82 | +; CHECK-NEXT: ret i32 [[V0]] |
| 83 | +; |
| 84 | + %v = call i64 @llvm.ptrauth.blend(i64 ptrtoint (ptr @f_both_disc.ref to i64), i64 0) |
| 85 | + %v0 = call i32 ptrauth(ptr @f, i32 1, i64 1234, ptr @f_both_disc.ref)(i32 %a0) [ "ptrauth"(i32 1, i64 %v) ] |
| 86 | + ret i32 %v0 |
| 87 | +} |
| 88 | + |
| 89 | +declare i64 @llvm.ptrauth.blend(i64, i64) |
0 commit comments