-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[InstCombine] Combine ptrauth constant callee into bundle. #94706
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py | ||
; RUN: opt < %s -passes=instcombine -S | FileCheck %s | ||
|
||
target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is manually specifying datalayout mandatory here or can we omit that? |
||
|
||
declare i64 @f(i32) | ||
declare ptr @f2(i32) | ||
|
||
define i32 @test_ptrauth_call(i32 %a0) { | ||
; CHECK-LABEL: @test_ptrauth_call( | ||
; CHECK-NEXT: [[V0:%.*]] = call i32 @f(i32 [[A0:%.*]]) | ||
; CHECK-NEXT: ret i32 [[V0]] | ||
; | ||
%v0 = call i32 ptrauth(ptr @f, i32 0)(i32 %a0) [ "ptrauth"(i32 0, i64 0) ] | ||
ret i32 %v0 | ||
} | ||
|
||
define i32 @test_ptrauth_call_disc(i32 %a0) { | ||
; CHECK-LABEL: @test_ptrauth_call_disc( | ||
; CHECK-NEXT: [[V0:%.*]] = call i32 @f(i32 [[A0:%.*]]) | ||
; CHECK-NEXT: ret i32 [[V0]] | ||
; | ||
%v0 = call i32 ptrauth(ptr @f, i32 1, i64 5678)(i32 %a0) [ "ptrauth"(i32 1, i64 5678) ] | ||
ret i32 %v0 | ||
} | ||
|
||
@f_addr_disc.ref = constant ptr ptrauth(ptr @f, i32 1, i64 0, ptr @f_addr_disc.ref) | ||
|
||
define i32 @test_ptrauth_call_addr_disc(i32 %a0) { | ||
; CHECK-LABEL: @test_ptrauth_call_addr_disc( | ||
; CHECK-NEXT: [[V0:%.*]] = call i32 @f(i32 [[A0:%.*]]) | ||
; CHECK-NEXT: ret i32 [[V0]] | ||
; | ||
%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)) ] | ||
ret i32 %v0 | ||
} | ||
|
||
@f_both_disc.ref = constant ptr ptrauth(ptr @f, i32 1, i64 1234, ptr @f_both_disc.ref) | ||
|
||
define i32 @test_ptrauth_call_blend(i32 %a0) { | ||
; CHECK-LABEL: @test_ptrauth_call_blend( | ||
; CHECK-NEXT: [[V0:%.*]] = call i32 @f(i32 [[A0:%.*]]) | ||
; CHECK-NEXT: ret i32 [[V0]] | ||
; | ||
%v = call i64 @llvm.ptrauth.blend(i64 ptrtoint (ptr @f_both_disc.ref to i64), i64 1234) | ||
%v0 = call i32 ptrauth(ptr @f, i32 1, i64 1234, ptr @f_both_disc.ref)(i32 %a0) [ "ptrauth"(i32 1, i64 %v) ] | ||
ret i32 %v0 | ||
} | ||
|
||
define i64 @test_ptrauth_call_cast(i32 %a0) { | ||
; CHECK-LABEL: @test_ptrauth_call_cast( | ||
; CHECK-NEXT: [[V0:%.*]] = call ptr @f2(i32 [[A0:%.*]]) | ||
; CHECK-NEXT: [[TMP1:%.*]] = ptrtoint ptr [[V0]] to i64 | ||
; CHECK-NEXT: ret i64 [[TMP1]] | ||
; | ||
%v0 = call i64 ptrauth(ptr @f2, i32 0)(i32 %a0) [ "ptrauth"(i32 0, i64 0) ] | ||
ret i64 %v0 | ||
} | ||
|
||
define i32 @test_ptrauth_call_mismatch_key(i32 %a0) { | ||
; CHECK-LABEL: @test_ptrauth_call_mismatch_key( | ||
; CHECK-NEXT: [[V0:%.*]] = call i32 ptrauth (ptr @f, i32 1, i64 5678)(i32 [[A0:%.*]]) [ "ptrauth"(i32 0, i64 5678) ] | ||
; CHECK-NEXT: ret i32 [[V0]] | ||
; | ||
%v0 = call i32 ptrauth(ptr @f, i32 1, i64 5678)(i32 %a0) [ "ptrauth"(i32 0, i64 5678) ] | ||
ret i32 %v0 | ||
} | ||
|
||
define i32 @test_ptrauth_call_mismatch_disc(i32 %a0) { | ||
; CHECK-LABEL: @test_ptrauth_call_mismatch_disc( | ||
; CHECK-NEXT: [[V0:%.*]] = call i32 ptrauth (ptr @f, i32 1, i64 5678)(i32 [[A0:%.*]]) [ "ptrauth"(i32 1, i64 0) ] | ||
; CHECK-NEXT: ret i32 [[V0]] | ||
; | ||
%v0 = call i32 ptrauth(ptr @f, i32 1, i64 5678)(i32 %a0) [ "ptrauth"(i32 1, i64 0) ] | ||
ret i32 %v0 | ||
} | ||
|
||
define i32 @test_ptrauth_call_mismatch_blend(i32 %a0) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would probably be nice to have one more test for mismatched blended address discriminator. Now, the address part is the same, and the 16-bit extra discrimination mismatches. It's probably worth testing that when extra discriminators match but address discriminators don't, we also fail. I'm OK with both adding tests as a part of this PR and submitting a follow-up patch with missing tests if adding them now is too time-consuming or there are other issues preventing that. |
||
; CHECK-LABEL: @test_ptrauth_call_mismatch_blend( | ||
; CHECK-NEXT: [[V:%.*]] = call i64 @llvm.ptrauth.blend(i64 ptrtoint (ptr @f_both_disc.ref to i64), i64 0) | ||
; CHECK-NEXT: [[V0:%.*]] = call i32 ptrauth (ptr @f, i32 1, i64 1234, ptr @f_both_disc.ref)(i32 [[A0:%.*]]) [ "ptrauth"(i32 1, i64 [[V]]) ] | ||
; CHECK-NEXT: ret i32 [[V0]] | ||
; | ||
%v = call i64 @llvm.ptrauth.blend(i64 ptrtoint (ptr @f_both_disc.ref to i64), i64 0) | ||
%v0 = call i32 ptrauth(ptr @f, i32 1, i64 1234, ptr @f_both_disc.ref)(i32 %a0) [ "ptrauth"(i32 1, i64 %v) ] | ||
ret i32 %v0 | ||
} | ||
|
||
declare i64 @llvm.ptrauth.blend(i64, i64) |
Uh oh!
There was an error while loading. Please reload this page.