brintos

brintos / llvm-project-archived public Read only

0
0
Text · 8.8 KiB · 22c330f Raw
204 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py2; RUN: opt < %s -passes=instcombine -S | FileCheck %s3 4define i64 @test_ptrauth_nop(ptr %p) {5; CHECK-LABEL: @test_ptrauth_nop(6; CHECK-NEXT:    [[TMP0:%.*]] = ptrtoint ptr [[P:%.*]] to i647; CHECK-NEXT:    ret i64 [[TMP0]]8;9  %tmp0 = ptrtoint ptr %p to i6410  %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 %authed13}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 %authed24}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 i6431  %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 %authed34}35 36define i64 @test_ptrauth_nop_mismatch(ptr %p) {37; CHECK-LABEL: @test_ptrauth_nop_mismatch(38; CHECK-NEXT:    [[TMP0:%.*]] = ptrtoint ptr [[P:%.*]] to i6439; 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 i6444  %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 %authed47}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 i6452; 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 i6457  %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 %authed60}61 62define i64 @test_ptrauth_sign_resign(ptr %p) {63; CHECK-LABEL: @test_ptrauth_sign_resign(64; CHECK-NEXT:    [[TMP0:%.*]] = ptrtoint ptr [[P:%.*]] to i6465; 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 i6469  %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 %authed72}73 74define i64 @test_ptrauth_resign_resign(ptr %p) {75; CHECK-LABEL: @test_ptrauth_resign_resign(76; CHECK-NEXT:    [[TMP0:%.*]] = ptrtoint ptr [[P:%.*]] to i6477; 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 i6481  %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 %authed84}85 86define i64 @test_ptrauth_resign_auth(ptr %p) {87; CHECK-LABEL: @test_ptrauth_resign_auth(88; CHECK-NEXT:    [[TMP0:%.*]] = ptrtoint ptr [[P:%.*]] to i6489; 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 i6493  %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 %authed96}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 i64101; 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 i64106  %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 %authed109}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 %authed118}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 %authed127}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 i64136  %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 %authed139}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 i64148  %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 %authed151}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 i64159  %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 %authed161}162 163@ds = external global i8164 165define i64 @test_ptrauth_nop_ds1(ptr %p) {166; CHECK-LABEL: @test_ptrauth_nop_ds1(167; CHECK-NEXT:    [[TMP0:%.*]] = ptrtoint ptr [[P:%.*]] to i64168; CHECK-NEXT:    [[SIGNED:%.*]] = call i64 @llvm.ptrauth.sign(i64 [[TMP0]], i32 1, i64 1234) [ "deactivation-symbol"(ptr @ds) ]169; CHECK-NEXT:    [[AUTHED:%.*]] = call i64 @llvm.ptrauth.auth(i64 [[SIGNED]], i32 1, i64 1234)170; CHECK-NEXT:    ret i64 [[AUTHED]]171;172  %tmp0 = ptrtoint ptr %p to i64173  %signed = call i64 @llvm.ptrauth.sign(i64 %tmp0, i32 1, i64 1234) [ "deactivation-symbol"(ptr @ds) ]174  %authed = call i64 @llvm.ptrauth.auth(i64 %signed, i32 1, i64 1234)175  ret i64 %authed176}177 178define i64 @test_ptrauth_nop_ds2(ptr %p) {179; CHECK-LABEL: @test_ptrauth_nop_ds2(180; CHECK-NEXT:    [[TMP0:%.*]] = ptrtoint ptr [[P:%.*]] to i64181; CHECK-NEXT:    [[SIGNED:%.*]] = call i64 @llvm.ptrauth.sign(i64 [[TMP0]], i32 1, i64 1234)182; CHECK-NEXT:    [[AUTHED:%.*]] = call i64 @llvm.ptrauth.auth(i64 [[SIGNED]], i32 1, i64 1234) [ "deactivation-symbol"(ptr @ds) ]183; CHECK-NEXT:    ret i64 [[AUTHED]]184;185  %tmp0 = ptrtoint ptr %p to i64186  %signed = call i64 @llvm.ptrauth.sign(i64 %tmp0, i32 1, i64 1234)187  %authed = call i64 @llvm.ptrauth.auth(i64 %signed, i32 1, i64 1234) [ "deactivation-symbol"(ptr @ds) ]188  ret i64 %authed189}190 191define i64 @test_ptrauth_nop_ds_constant() {192; CHECK-LABEL: @test_ptrauth_nop_ds_constant(193; CHECK-NEXT:    [[AUTHED:%.*]] = call i64 @llvm.ptrauth.auth(i64 ptrtoint (ptr ptrauth (ptr @foo, i32 1, i64 1234, ptr null, ptr @ds) to i64), i32 1, i64 1234)194; CHECK-NEXT:    ret i64 [[AUTHED]]195;196  %authed = call i64 @llvm.ptrauth.auth(i64 ptrtoint(ptr ptrauth(ptr @foo, i32 1, i64 1234, ptr null, ptr @ds) to i64), i32 1, i64 1234)197  ret i64 %authed198}199 200declare i64 @llvm.ptrauth.auth(i64, i32, i64)201declare i64 @llvm.ptrauth.sign(i64, i32, i64)202declare i64 @llvm.ptrauth.resign(i64, i32, i64, i32, i64)203declare i64 @llvm.ptrauth.blend(i64, i64)204