1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 2; RUN: opt < %s -passes=instcombine -S | FileCheck %s 3 4define i64 @test_ptrauth_nop(ptr %p) { 5; CHECK-LABEL: @test_ptrauth_nop( 6; CHECK-NEXT: [[TMP0:%.*]] = ptrtoint ptr [[P:%.*]] to i64 7; CHECK-NEXT: ret i64 [[TMP0]] 8; 9 %tmp0 = ptrtoint ptr %p to i64 10 %signed = call i64 @llvm.ptrauth.sign(i64 %tmp0, i32 1, i64 1234) 11 %authed = call i64 @llvm.ptrauth.auth(i64 %signed, i32 1, i64 1234) 12 ret i64 %authed 13} 14 15declare void @foo() 16declare void @bar() 17 18define i64 @test_ptrauth_nop_constant() { 19; CHECK-LABEL: @test_ptrauth_nop_constant( 20; CHECK-NEXT: ret i64 ptrtoint (ptr @foo to i64) 21; 22 %authed = call i64 @llvm.ptrauth.auth(i64 ptrtoint(ptr ptrauth(ptr @foo, i32 1, i64 1234) to i64), i32 1, i64 1234) 23 ret i64 %authed 24} 25 26define i64 @test_ptrauth_nop_constant_addrdisc() { 27; CHECK-LABEL: @test_ptrauth_nop_constant_addrdisc( 28; CHECK-NEXT: ret i64 ptrtoint (ptr @foo to i64) 29; 30 %addr = ptrtoint ptr @foo to i64 31 %blended = call i64 @llvm.ptrauth.blend(i64 %addr, i64 1234) 32 %authed = call i64 @llvm.ptrauth.auth(i64 ptrtoint(ptr ptrauth(ptr @foo, i32 1, i64 1234, ptr @foo) to i64), i32 1, i64 %blended) 33 ret i64 %authed 34} 35 36define i64 @test_ptrauth_nop_mismatch(ptr %p) { 37; CHECK-LABEL: @test_ptrauth_nop_mismatch( 38; CHECK-NEXT: [[TMP0:%.*]] = ptrtoint ptr [[P:%.*]] to i64 39; CHECK-NEXT: [[SIGNED:%.*]] = call i64 @llvm.ptrauth.sign(i64 [[TMP0]], i32 1, i64 1234) 40; CHECK-NEXT: [[AUTHED:%.*]] = call i64 @llvm.ptrauth.auth(i64 [[SIGNED]], i32 1, i64 10) 41; CHECK-NEXT: ret i64 [[AUTHED]] 42; 43 %tmp0 = ptrtoint ptr %p to i64 44 %signed = call i64 @llvm.ptrauth.sign(i64 %tmp0, i32 1, i64 1234) 45 %authed = call i64 @llvm.ptrauth.auth(i64 %signed, i32 1, i64 10) 46 ret i64 %authed 47} 48 49define i64 @test_ptrauth_nop_mismatch_keys(ptr %p) { 50; CHECK-LABEL: @test_ptrauth_nop_mismatch_keys( 51; CHECK-NEXT: [[TMP0:%.*]] = ptrtoint ptr [[P:%.*]] to i64 52; CHECK-NEXT: [[SIGNED:%.*]] = call i64 @llvm.ptrauth.sign(i64 [[TMP0]], i32 0, i64 1234) 53; CHECK-NEXT: [[AUTHED:%.*]] = call i64 @llvm.ptrauth.auth(i64 [[SIGNED]], i32 1, i64 1234) 54; CHECK-NEXT: ret i64 [[AUTHED]] 55; 56 %tmp0 = ptrtoint ptr %p to i64 57 %signed = call i64 @llvm.ptrauth.sign(i64 %tmp0, i32 0, i64 1234) 58 %authed = call i64 @llvm.ptrauth.auth(i64 %signed, i32 1, i64 1234) 59 ret i64 %authed 60} 61 62define i64 @test_ptrauth_sign_resign(ptr %p) { 63; CHECK-LABEL: @test_ptrauth_sign_resign( 64; CHECK-NEXT: [[TMP0:%.*]] = ptrtoint ptr [[P:%.*]] to i64 65; CHECK-NEXT: [[AUTHED:%.*]] = call i64 @llvm.ptrauth.sign(i64 [[TMP0]], i32 0, i64 42) 66; CHECK-NEXT: ret i64 [[AUTHED]] 67; 68 %tmp0 = ptrtoint ptr %p to i64 69 %signed = call i64 @llvm.ptrauth.sign(i64 %tmp0, i32 1, i64 1234) 70 %authed = call i64 @llvm.ptrauth.resign(i64 %signed, i32 1, i64 1234, i32 0, i64 42) 71 ret i64 %authed 72} 73 74define i64 @test_ptrauth_resign_resign(ptr %p) { 75; CHECK-LABEL: @test_ptrauth_resign_resign( 76; CHECK-NEXT: [[TMP0:%.*]] = ptrtoint ptr [[P:%.*]] to i64 77; CHECK-NEXT: [[AUTHED:%.*]] = call i64 @llvm.ptrauth.resign(i64 [[TMP0]], i32 1, i64 1234, i32 1, i64 3141) 78; CHECK-NEXT: ret i64 [[AUTHED]] 79; 80 %tmp0 = ptrtoint ptr %p to i64 81 %signed = call i64 @llvm.ptrauth.resign(i64 %tmp0, i32 1, i64 1234, i32 0, i64 42) 82 %authed = call i64 @llvm.ptrauth.resign(i64 %signed, i32 0, i64 42, i32 1, i64 3141) 83 ret i64 %authed 84} 85 86define i64 @test_ptrauth_resign_auth(ptr %p) { 87; CHECK-LABEL: @test_ptrauth_resign_auth( 88; CHECK-NEXT: [[TMP0:%.*]] = ptrtoint ptr [[P:%.*]] to i64 89; CHECK-NEXT: [[AUTHED:%.*]] = call i64 @llvm.ptrauth.auth(i64 [[TMP0]], i32 1, i64 1234) 90; CHECK-NEXT: ret i64 [[AUTHED]] 91; 92 %tmp0 = ptrtoint ptr %p to i64 93 %signed = call i64 @llvm.ptrauth.resign(i64 %tmp0, i32 1, i64 1234, i32 0, i64 42) 94 %authed = call i64 @llvm.ptrauth.auth(i64 %signed, i32 0, i64 42) 95 ret i64 %authed 96} 97 98define i64 @test_ptrauth_resign_auth_mismatch(ptr %p) { 99; CHECK-LABEL: @test_ptrauth_resign_auth_mismatch( 100; CHECK-NEXT: [[TMP0:%.*]] = ptrtoint ptr [[P:%.*]] to i64 101; CHECK-NEXT: [[SIGNED:%.*]] = call i64 @llvm.ptrauth.resign(i64 [[TMP0]], i32 1, i64 1234, i32 0, i64 10) 102; CHECK-NEXT: [[AUTHED:%.*]] = call i64 @llvm.ptrauth.auth(i64 [[SIGNED]], i32 0, i64 42) 103; CHECK-NEXT: ret i64 [[AUTHED]] 104; 105 %tmp0 = ptrtoint ptr %p to i64 106 %signed = call i64 @llvm.ptrauth.resign(i64 %tmp0, i32 1, i64 1234, i32 0, i64 10) 107 %authed = call i64 @llvm.ptrauth.auth(i64 %signed, i32 0, i64 42) 108 ret i64 %authed 109} 110 111define i64 @test_ptrauth_nop_constant_mismatch() { 112; CHECK-LABEL: @test_ptrauth_nop_constant_mismatch( 113; CHECK-NEXT: [[AUTHED:%.*]] = call i64 @llvm.ptrauth.auth(i64 ptrtoint (ptr ptrauth (ptr @foo, i32 1, i64 1234) to i64), i32 1, i64 12) 114; CHECK-NEXT: ret i64 [[AUTHED]] 115; 116 %authed = call i64 @llvm.ptrauth.auth(i64 ptrtoint(ptr ptrauth(ptr @foo, i32 1, i64 1234) to i64), i32 1, i64 12) 117 ret i64 %authed 118} 119 120define i64 @test_ptrauth_nop_constant_mismatch_key() { 121; CHECK-LABEL: @test_ptrauth_nop_constant_mismatch_key( 122; CHECK-NEXT: [[AUTHED:%.*]] = call i64 @llvm.ptrauth.auth(i64 ptrtoint (ptr ptrauth (ptr @foo, i32 1, i64 1234) to i64), i32 0, i64 1234) 123; CHECK-NEXT: ret i64 [[AUTHED]] 124; 125 %authed = call i64 @llvm.ptrauth.auth(i64 ptrtoint(ptr ptrauth(ptr @foo, i32 1, i64 1234) to i64), i32 0, i64 1234) 126 ret i64 %authed 127} 128 129define i64 @test_ptrauth_nop_constant_addrdisc_mismatch() { 130; CHECK-LABEL: @test_ptrauth_nop_constant_addrdisc_mismatch( 131; CHECK-NEXT: [[BLENDED:%.*]] = call i64 @llvm.ptrauth.blend(i64 ptrtoint (ptr @foo to i64), i64 12) 132; CHECK-NEXT: [[AUTHED:%.*]] = call i64 @llvm.ptrauth.auth(i64 ptrtoint (ptr ptrauth (ptr @foo, i32 1, i64 1234, ptr @foo) to i64), i32 1, i64 [[BLENDED]]) 133; CHECK-NEXT: ret i64 [[AUTHED]] 134; 135 %addr = ptrtoint ptr @foo to i64 136 %blended = call i64 @llvm.ptrauth.blend(i64 %addr, i64 12) 137 %authed = call i64 @llvm.ptrauth.auth(i64 ptrtoint(ptr ptrauth(ptr @foo, i32 1, i64 1234, ptr @foo) to i64), i32 1, i64 %blended) 138 ret i64 %authed 139} 140 141define i64 @test_ptrauth_nop_constant_addrdisc_mismatch2() { 142; CHECK-LABEL: @test_ptrauth_nop_constant_addrdisc_mismatch2( 143; CHECK-NEXT: [[BLENDED:%.*]] = call i64 @llvm.ptrauth.blend(i64 ptrtoint (ptr @bar to i64), i64 1234) 144; CHECK-NEXT: [[AUTHED:%.*]] = call i64 @llvm.ptrauth.auth(i64 ptrtoint (ptr ptrauth (ptr @foo, i32 1, i64 1234, ptr @foo) to i64), i32 1, i64 [[BLENDED]]) 145; CHECK-NEXT: ret i64 [[AUTHED]] 146; 147 %addr = ptrtoint ptr @bar to i64 148 %blended = call i64 @llvm.ptrauth.blend(i64 %addr, i64 1234) 149 %authed = call i64 @llvm.ptrauth.auth(i64 ptrtoint(ptr ptrauth(ptr @foo, i32 1, i64 1234, ptr @foo) to i64), i32 1, i64 %blended) 150 ret i64 %authed 151} 152 153define i64 @test_ptrauth_resign_ptrauth_constant(ptr %p) { 154; CHECK-LABEL: @test_ptrauth_resign_ptrauth_constant( 155; CHECK-NEXT: ret i64 ptrtoint (ptr ptrauth (ptr @foo, i32 0, i64 42) to i64) 156; 157 158 %tmp0 = ptrtoint ptr %p to i64 159 %authed = call i64 @llvm.ptrauth.resign(i64 ptrtoint(ptr ptrauth(ptr @foo, i32 1, i64 1234) to i64), i32 1, i64 1234, i32 0, i64 42) 160 ret i64 %authed 161} 162 163declare i64 @llvm.ptrauth.auth(i64, i32, i64) 164declare i64 @llvm.ptrauth.sign(i64, i32, i64) 165declare i64 @llvm.ptrauth.resign(i64, i32, i64, i32, i64) 166declare i64 @llvm.ptrauth.blend(i64, i64) 167