Skip to content

Commit 04e4d83

Browse files
committed
[PAC][InstCombine] Precommit tests for replacing auth+sign with resign
1 parent 111af76 commit 04e4d83

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

llvm/test/Transforms/InstCombine/ptrauth-intrinsics.ll

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,68 @@ define i64 @test_ptrauth_resign_ptrauth_constant(ptr %p) {
160160
ret i64 %authed
161161
}
162162

163+
define i64 @test_ptrauth_auth_sign_same_schema(ptr %p) {
164+
; CHECK-LABEL: @test_ptrauth_auth_sign_same_schema(
165+
; CHECK-NEXT: [[P_INT:%.*]] = ptrtoint ptr [[P:%.*]] to i64
166+
; CHECK-NEXT: [[AUTHED:%.*]] = call i64 @llvm.ptrauth.auth(i64 [[P_INT]], i32 1, i64 1234)
167+
; CHECK-NEXT: [[RESIGNED:%.*]] = call i64 @llvm.ptrauth.sign(i64 [[AUTHED]], i32 1, i64 1234)
168+
; CHECK-NEXT: ret i64 [[RESIGNED]]
169+
;
170+
%p.int = ptrtoint ptr %p to i64
171+
%authed = call i64 @llvm.ptrauth.auth(i64 %p.int, i32 1, i64 1234)
172+
%resigned = call i64 @llvm.ptrauth.sign(i64 %authed, i32 1, i64 1234)
173+
ret i64 %resigned
174+
}
175+
176+
define i64 @test_ptrauth_auth_sign_opaque_disc_same_schema(ptr %p, i64 %disc) {
177+
; CHECK-LABEL: @test_ptrauth_auth_sign_opaque_disc_same_schema(
178+
; CHECK-NEXT: [[P_INT:%.*]] = ptrtoint ptr [[P:%.*]] to i64
179+
; CHECK-NEXT: [[AUTHED:%.*]] = call i64 @llvm.ptrauth.auth(i64 [[P_INT]], i32 1, i64 [[DISC:%.*]])
180+
; CHECK-NEXT: [[RESIGNED:%.*]] = call i64 @llvm.ptrauth.sign(i64 [[AUTHED]], i32 1, i64 [[DISC]])
181+
; CHECK-NEXT: ret i64 [[RESIGNED]]
182+
;
183+
%p.int = ptrtoint ptr %p to i64
184+
%authed = call i64 @llvm.ptrauth.auth(i64 %p.int, i32 1, i64 %disc)
185+
%resigned = call i64 @llvm.ptrauth.sign(i64 %authed, i32 1, i64 %disc)
186+
ret i64 %resigned
187+
}
188+
189+
define i64 @test_ptrauth_auth_sign_different_disc(ptr %p, i64 %disc) {
190+
; CHECK-LABEL: @test_ptrauth_auth_sign_different_disc(
191+
; CHECK-NEXT: [[P_INT:%.*]] = ptrtoint ptr [[P:%.*]] to i64
192+
; CHECK-NEXT: [[AUTHED:%.*]] = call i64 @llvm.ptrauth.auth(i64 [[P_INT]], i32 1, i64 [[DISC:%.*]])
193+
; CHECK-NEXT: [[RESIGNED:%.*]] = call i64 @llvm.ptrauth.sign(i64 [[AUTHED]], i32 1, i64 1234)
194+
; CHECK-NEXT: ret i64 [[RESIGNED]]
195+
;
196+
%p.int = ptrtoint ptr %p to i64
197+
%authed = call i64 @llvm.ptrauth.auth(i64 %p.int, i32 1, i64 %disc)
198+
%resigned = call i64 @llvm.ptrauth.sign(i64 %authed, i32 1, i64 1234)
199+
ret i64 %resigned
200+
}
201+
202+
define i64 @test_ptrauth_auth_sign_different_key(ptr %p) {
203+
; CHECK-LABEL: @test_ptrauth_auth_sign_different_key(
204+
; CHECK-NEXT: [[P_INT:%.*]] = ptrtoint ptr [[P:%.*]] to i64
205+
; CHECK-NEXT: [[AUTHED:%.*]] = call i64 @llvm.ptrauth.auth(i64 [[P_INT]], i32 0, i64 1234)
206+
; CHECK-NEXT: [[RESIGNED:%.*]] = call i64 @llvm.ptrauth.sign(i64 [[AUTHED]], i32 1, i64 1234)
207+
; CHECK-NEXT: ret i64 [[RESIGNED]]
208+
;
209+
%p.int = ptrtoint ptr %p to i64
210+
%authed = call i64 @llvm.ptrauth.auth(i64 %p.int, i32 0, i64 1234)
211+
%resigned = call i64 @llvm.ptrauth.sign(i64 %authed, i32 1, i64 1234)
212+
ret i64 %resigned
213+
}
214+
215+
define i64 @test_ptrauth_sign_nonauth_nonconst_disc(i64 %disc) {
216+
; CHECK-LABEL: @test_ptrauth_sign_nonauth_nonconst_disc(
217+
; CHECK-NEXT: [[SIGNED:%.*]] = call i64 @llvm.ptrauth.sign(i64 ptrtoint (ptr @foo to i64), i32 1, i64 [[DISC:%.*]])
218+
; CHECK-NEXT: ret i64 [[SIGNED]]
219+
;
220+
%foo.int = ptrtoint ptr @foo to i64
221+
%signed = call i64 @llvm.ptrauth.sign(i64 %foo.int, i32 1, i64 %disc)
222+
ret i64 %signed
223+
}
224+
163225
declare i64 @llvm.ptrauth.auth(i64, i32, i64)
164226
declare i64 @llvm.ptrauth.sign(i64, i32, i64)
165227
declare i64 @llvm.ptrauth.resign(i64, i32, i64, i32, i64)

0 commit comments

Comments
 (0)