Skip to content

Commit

Permalink
[test][PAC][AArch64] Add ELF tests for subtarget-neutral codegen (llv…
Browse files Browse the repository at this point in the history
…m#98020)

Many parts of PAuth-related codegen are not MachO- or ELF-specific. Add
RUN lines against ELF targets to ensure that codegen works for ELF as
well as for MachO.
  • Loading branch information
kovdan01 committed Jul 9, 2024
1 parent 1adb55b commit 746f572
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 48 deletions.
59 changes: 38 additions & 21 deletions llvm/test/CodeGen/AArch64/ptrauth-bti-call.ll
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
; RUN: llc -mtriple arm64e-apple-darwin -mattr=+bti -asm-verbose=false -o - %s | FileCheck %s
; RUN: llc -mtriple arm64e-apple-darwin -mattr=+bti -global-isel -asm-verbose=false -o - %s | FileCheck %s
; RUN: llc -mtriple arm64e-apple-darwin -mattr=+bti -fast-isel -asm-verbose=false -o - %s | FileCheck %s
; RUN: llc -mtriple arm64e-apple-darwin -mattr=+bti -asm-verbose=false \
; RUN: -o - %s | FileCheck %s --check-prefixes=DARWIN,CHECK
; RUN: llc -mtriple arm64e-apple-darwin -mattr=+bti -global-isel -asm-verbose=false \
; RUN: -o - %s | FileCheck %s --check-prefixes=DARWIN,CHECK
; RUN: llc -mtriple arm64e-apple-darwin -mattr=+bti -fast-isel -asm-verbose=false \
; RUN: -o - %s | FileCheck %s --check-prefixes=DARWIN,CHECK
; RUN: llc -mtriple aarch64-linux-gnu -mattr=+bti -mattr=+pauth -asm-verbose=false \
; RUN: -o - %s | FileCheck %s --check-prefixes=ELF,CHECK
; RUN: llc -mtriple aarch64-linux-gnu -mattr=+bti -mattr=+pauth -global-isel -asm-verbose=false \
; RUN: -o - %s | FileCheck %s --check-prefixes=ELF,CHECK
; RUN: llc -mtriple aarch64-linux-gnu -mattr=+bti -mattr=+pauth -fast-isel -asm-verbose=false \
; RUN: -o - %s | FileCheck %s --check-prefixes=ELF,CHECK

; ptrauth tail-calls can only use x16/x17 with BTI.

; CHECK-LABEL: _test_tailcall_ia_0:
; CHECK-LABEL: test_tailcall_ia_0:
; CHECK-NEXT: bti c
; CHECK-NEXT: mov x16, x0
; CHECK-NEXT: braaz x16
Expand All @@ -13,7 +22,7 @@ define i32 @test_tailcall_ia_0(i32 ()* %arg0) #0 {
ret i32 %tmp0
}

; CHECK-LABEL: _test_tailcall_ib_0:
; CHECK-LABEL: test_tailcall_ib_0:
; CHECK-NEXT: bti c
; CHECK-NEXT: mov x16, x0
; CHECK-NEXT: brabz x16
Expand All @@ -22,7 +31,7 @@ define i32 @test_tailcall_ib_0(i32 ()* %arg0) #0 {
ret i32 %tmp0
}

; CHECK-LABEL: _test_tailcall_ia_imm:
; CHECK-LABEL: test_tailcall_ia_imm:
; CHECK-NEXT: bti c
; CHECK-NEXT: mov x16, x0
; CHECK-NEXT: mov x17, #42
Expand All @@ -32,7 +41,7 @@ define i32 @test_tailcall_ia_imm(i32 ()* %arg0) #0 {
ret i32 %tmp0
}

; CHECK-LABEL: _test_tailcall_ib_imm:
; CHECK-LABEL: test_tailcall_ib_imm:
; CHECK-NEXT: bti c
; CHECK-NEXT: mov x16, x0
; CHECK-NEXT: mov x17, #42
Expand All @@ -42,29 +51,37 @@ define i32 @test_tailcall_ib_imm(i32 ()* %arg0) #0 {
ret i32 %tmp0
}

; CHECK-LABEL: _test_tailcall_ia_var:
; CHECK-NEXT: bti c
; CHECK-NEXT: mov x16, x0
; CHECK-NEXT: ldr x0, [x1]
; CHECK-NEXT: braa x16, x0
; CHECK-LABEL: test_tailcall_ia_var:
; DARWIN-NEXT: bti c
; DARWIN-NEXT: mov x16, x0
; DARWIN-NEXT: ldr x0, [x1]
; DARWIN-NEXT: braa x16, x0
; ELF-NEXT: bti c
; ELF-NEXT: ldr x1, [x1]
; ELF-NEXT: mov x16, x0
; ELF-NEXT: braa x16, x1
define i32 @test_tailcall_ia_var(i32 ()* %arg0, i64* %arg1) #0 {
%tmp0 = load i64, i64* %arg1
%tmp1 = tail call i32 %arg0() [ "ptrauth"(i32 0, i64 %tmp0) ]
ret i32 %tmp1
}

; CHECK-LABEL: _test_tailcall_ib_var:
; CHECK-NEXT: bti c
; CHECK-NEXT: mov x16, x0
; CHECK-NEXT: ldr x0, [x1]
; CHECK-NEXT: brab x16, x0
; CHECK-LABEL: test_tailcall_ib_var:
; DARWIN-NEXT: bti c
; DARWIN-NEXT: mov x16, x0
; DARWIN-NEXT: ldr x0, [x1]
; DARWIN-NEXT: brab x16, x0
; ELF-NEXT: bti c
; ELF-NEXT: ldr x1, [x1]
; ELF-NEXT: mov x16, x0
; ELF-NEXT: brab x16, x1
define i32 @test_tailcall_ib_var(i32 ()* %arg0, i64* %arg1) #0 {
%tmp0 = load i64, i64* %arg1
%tmp1 = tail call i32 %arg0() [ "ptrauth"(i32 1, i64 %tmp0) ]
ret i32 %tmp1
}

; CHECK-LABEL: _test_tailcall_ia_arg:
; CHECK-LABEL: test_tailcall_ia_arg:
; CHECK-NEXT: bti c
; CHECK-NEXT: mov x16, x0
; CHECK-NEXT: braa x16, x1
Expand All @@ -73,7 +90,7 @@ define i32 @test_tailcall_ia_arg(i32 ()* %arg0, i64 %arg1) #0 {
ret i32 %tmp0
}

; CHECK-LABEL: _test_tailcall_ib_arg:
; CHECK-LABEL: test_tailcall_ib_arg:
; CHECK-NEXT: bti c
; CHECK-NEXT: mov x16, x0
; CHECK-NEXT: brab x16, x1
Expand All @@ -82,7 +99,7 @@ define i32 @test_tailcall_ib_arg(i32 ()* %arg0, i64 %arg1) #0 {
ret i32 %tmp0
}

; CHECK-LABEL: _test_tailcall_ia_arg_ind:
; CHECK-LABEL: test_tailcall_ia_arg_ind:
; CHECK-NEXT: bti c
; CHECK-NEXT: ldr x16, [x0]
; CHECK-NEXT: braa x16, x1
Expand All @@ -92,7 +109,7 @@ define i32 @test_tailcall_ia_arg_ind(i32 ()** %arg0, i64 %arg1) #0 {
ret i32 %tmp1
}

; CHECK-LABEL: _test_tailcall_ib_arg_ind:
; CHECK-LABEL: test_tailcall_ib_arg_ind:
; CHECK-NEXT: bti c
; CHECK-NEXT: ldr x16, [x0]
; CHECK-NEXT: brab x16, x1
Expand Down
14 changes: 8 additions & 6 deletions llvm/test/CodeGen/AArch64/ptrauth-intrinsic-blend.ll
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
; RUN: llc < %s -mtriple arm64e-apple-darwin -verify-machineinstrs -global-isel=0 | FileCheck %s
; RUN: llc < %s -mtriple arm64e-apple-darwin -verify-machineinstrs -global-isel=1 -global-isel-abort=1 | FileCheck %s
; RUN: llc < %s -mtriple arm64e-apple-darwin -verify-machineinstrs -global-isel=0 | FileCheck %s
; RUN: llc < %s -mtriple arm64e-apple-darwin -verify-machineinstrs -global-isel=1 -global-isel-abort=1 | FileCheck %s
; RUN: llc < %s -mtriple aarch64-linux-gnu -mattr=+pauth -verify-machineinstrs -global-isel=0 | FileCheck %s
; RUN: llc < %s -mtriple aarch64-linux-gnu -mattr=+pauth -verify-machineinstrs -global-isel=1 -global-isel-abort=1 | FileCheck %s

define i64 @test_blend(i64 %arg, i64 %arg1) {
; CHECK-LABEL: test_blend:
; CHECK: ; %bb.0:
; CHECK: %bb.0:
; CHECK-NEXT: bfi x0, x1, #48, #16
; CHECK-NEXT: ret
%tmp = call i64 @llvm.ptrauth.blend(i64 %arg, i64 %arg1)
Expand All @@ -13,7 +15,7 @@ define i64 @test_blend(i64 %arg, i64 %arg1) {

define i64 @test_blend_constant(i64 %arg) {
; CHECK-LABEL: test_blend_constant:
; CHECK: ; %bb.0:
; CHECK: %bb.0:
; CHECK-NEXT: movk x0, #12345, lsl #48
; CHECK-NEXT: ret
%tmp = call i64 @llvm.ptrauth.blend(i64 %arg, i64 12345)
Expand All @@ -23,7 +25,7 @@ define i64 @test_blend_constant(i64 %arg) {
; Blend isn't commutative.
define i64 @test_blend_constant_swapped(i64 %arg) {
; CHECK-LABEL: test_blend_constant_swapped:
; CHECK: ; %bb.0:
; CHECK: %bb.0:
; CHECK-NEXT: mov w8, #12345
; CHECK-NEXT: bfi x8, x0, #48, #16
; CHECK-NEXT: mov x0, x8
Expand All @@ -35,7 +37,7 @@ define i64 @test_blend_constant_swapped(i64 %arg) {
; Blends of constants wider than 16 bits truncate the constant.
define i64 @test_blend_constant_wide(i64 %arg) {
; CHECK-LABEL: test_blend_constant_wide:
; CHECK: ; %bb.0:
; CHECK: %bb.0:
; CHECK-NEXT: mov w8, #65536
; CHECK-NEXT: bfi x0, x8, #48, #16
; CHECK-NEXT: ret
Expand Down
8 changes: 5 additions & 3 deletions llvm/test/CodeGen/AArch64/ptrauth-intrinsic-sign-generic.ll
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
; RUN: llc < %s -mtriple arm64e-apple-darwin -verify-machineinstrs -global-isel=0 | FileCheck %s
; RUN: llc < %s -mtriple arm64e-apple-darwin -verify-machineinstrs -global-isel=1 -global-isel-abort=1 | FileCheck %s
; RUN: llc < %s -mtriple arm64e-apple-darwin -verify-machineinstrs -global-isel=0 | FileCheck %s
; RUN: llc < %s -mtriple arm64e-apple-darwin -verify-machineinstrs -global-isel=1 -global-isel-abort=1 | FileCheck %s
; RUN: llc < %s -mtriple aarch64-linux-gnu -mattr=+pauth -verify-machineinstrs -global-isel=0 | FileCheck %s
; RUN: llc < %s -mtriple aarch64-linux-gnu -mattr=+pauth -verify-machineinstrs -global-isel=1 -global-isel-abort=1 | FileCheck %s

define i64 @test_sign_generic(i64 %arg, i64 %arg1) {
; CHECK-LABEL: test_sign_generic:
; CHECK: ; %bb.0:
; CHECK: %bb.0:
; CHECK-NEXT: pacga x0, x0, x1
; CHECK-NEXT: ret
%tmp = call i64 @llvm.ptrauth.sign.generic(i64 %arg, i64 %arg1)
Expand Down
22 changes: 12 additions & 10 deletions llvm/test/CodeGen/AArch64/ptrauth-intrinsic-sign.ll
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
; RUN: llc < %s -mtriple arm64e-apple-darwin -verify-machineinstrs -global-isel=0 | FileCheck %s
; RUN: llc < %s -mtriple arm64e-apple-darwin -verify-machineinstrs -global-isel=1 -global-isel-abort=1 | FileCheck %s
; RUN: llc < %s -mtriple arm64e-apple-darwin -verify-machineinstrs -global-isel=0 | FileCheck %s
; RUN: llc < %s -mtriple arm64e-apple-darwin -verify-machineinstrs -global-isel=1 -global-isel-abort=1 | FileCheck %s
; RUN: llc < %s -mtriple aarch64-linux-gnu -mattr=+pauth -verify-machineinstrs -global-isel=0 | FileCheck %s
; RUN: llc < %s -mtriple aarch64-linux-gnu -mattr=+pauth -verify-machineinstrs -global-isel=1 -global-isel-abort=1 | FileCheck %s

define i64 @test_sign_ia(i64 %arg, i64 %arg1) {
; CHECK-LABEL: test_sign_ia:
; CHECK: ; %bb.0:
; CHECK: %bb.0:
; CHECK-NEXT: pacia x0, x1
; CHECK-NEXT: ret
%tmp = call i64 @llvm.ptrauth.sign(i64 %arg, i32 0, i64 %arg1)
Expand All @@ -13,7 +15,7 @@ define i64 @test_sign_ia(i64 %arg, i64 %arg1) {

define i64 @test_sign_ia_zero(i64 %arg) {
; CHECK-LABEL: test_sign_ia_zero:
; CHECK: ; %bb.0:
; CHECK: %bb.0:
; CHECK-NEXT: paciza x0
; CHECK-NEXT: ret
%tmp = call i64 @llvm.ptrauth.sign(i64 %arg, i32 0, i64 0)
Expand All @@ -22,7 +24,7 @@ define i64 @test_sign_ia_zero(i64 %arg) {

define i64 @test_sign_ib(i64 %arg, i64 %arg1) {
; CHECK-LABEL: test_sign_ib:
; CHECK: ; %bb.0:
; CHECK: %bb.0:
; CHECK-NEXT: pacib x0, x1
; CHECK-NEXT: ret
%tmp = call i64 @llvm.ptrauth.sign(i64 %arg, i32 1, i64 %arg1)
Expand All @@ -31,7 +33,7 @@ define i64 @test_sign_ib(i64 %arg, i64 %arg1) {

define i64 @test_sign_ib_zero(i64 %arg) {
; CHECK-LABEL: test_sign_ib_zero:
; CHECK: ; %bb.0:
; CHECK: %bb.0:
; CHECK-NEXT: pacizb x0
; CHECK-NEXT: ret
%tmp = call i64 @llvm.ptrauth.sign(i64 %arg, i32 1, i64 0)
Expand All @@ -40,7 +42,7 @@ define i64 @test_sign_ib_zero(i64 %arg) {

define i64 @test_sign_da(i64 %arg, i64 %arg1) {
; CHECK-LABEL: test_sign_da:
; CHECK: ; %bb.0:
; CHECK: %bb.0:
; CHECK-NEXT: pacda x0, x1
; CHECK-NEXT: ret
%tmp = call i64 @llvm.ptrauth.sign(i64 %arg, i32 2, i64 %arg1)
Expand All @@ -49,7 +51,7 @@ define i64 @test_sign_da(i64 %arg, i64 %arg1) {

define i64 @test_sign_da_zero(i64 %arg) {
; CHECK-LABEL: test_sign_da_zero:
; CHECK: ; %bb.0:
; CHECK: %bb.0:
; CHECK-NEXT: pacdza x0
; CHECK-NEXT: ret
%tmp = call i64 @llvm.ptrauth.sign(i64 %arg, i32 2, i64 0)
Expand All @@ -58,7 +60,7 @@ define i64 @test_sign_da_zero(i64 %arg) {

define i64 @test_sign_db(i64 %arg, i64 %arg1) {
; CHECK-LABEL: test_sign_db:
; CHECK: ; %bb.0:
; CHECK: %bb.0:
; CHECK-NEXT: pacdb x0, x1
; CHECK-NEXT: ret
%tmp = call i64 @llvm.ptrauth.sign(i64 %arg, i32 3, i64 %arg1)
Expand All @@ -67,7 +69,7 @@ define i64 @test_sign_db(i64 %arg, i64 %arg1) {

define i64 @test_sign_db_zero(i64 %arg) {
; CHECK-LABEL: test_sign_db_zero:
; CHECK: ; %bb.0:
; CHECK: %bb.0:
; CHECK-NEXT: pacdzb x0
; CHECK-NEXT: ret
%tmp = call i64 @llvm.ptrauth.sign(i64 %arg, i32 3, i64 0)
Expand Down
16 changes: 8 additions & 8 deletions llvm/test/CodeGen/AArch64/ptrauth-intrinsic-strip.ll
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
; RUN: llc < %s -mtriple arm64e-apple-darwin -verify-machineinstrs -global-isel=0 | FileCheck %s
; RUN: llc < %s -mtriple arm64e-apple-darwin -verify-machineinstrs -global-isel=1 -global-isel-abort=1 | FileCheck %s

target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128"
; RUN: llc < %s -mtriple arm64e-apple-darwin -verify-machineinstrs -global-isel=0 | FileCheck %s
; RUN: llc < %s -mtriple arm64e-apple-darwin -verify-machineinstrs -global-isel=1 -global-isel-abort=1 | FileCheck %s
; RUN: llc < %s -mtriple aarch64-linux-gnu -mattr=+pauth -verify-machineinstrs -global-isel=0 | FileCheck %s
; RUN: llc < %s -mtriple aarch64-linux-gnu -mattr=+pauth -verify-machineinstrs -global-isel=1 -global-isel-abort=1 | FileCheck %s

define i64 @test_strip_ia(i64 %arg) {
; CHECK-LABEL: test_strip_ia:
; CHECK: ; %bb.0:
; CHECK: %bb.0:
; CHECK-NEXT: xpaci x0
; CHECK-NEXT: ret
%tmp = call i64 @llvm.ptrauth.strip(i64 %arg, i32 0)
Expand All @@ -15,7 +15,7 @@ define i64 @test_strip_ia(i64 %arg) {

define i64 @test_strip_ib(i64 %arg) {
; CHECK-LABEL: test_strip_ib:
; CHECK: ; %bb.0:
; CHECK: %bb.0:
; CHECK-NEXT: xpaci x0
; CHECK-NEXT: ret
%tmp = call i64 @llvm.ptrauth.strip(i64 %arg, i32 1)
Expand All @@ -24,7 +24,7 @@ define i64 @test_strip_ib(i64 %arg) {

define i64 @test_strip_da(i64 %arg) {
; CHECK-LABEL: test_strip_da:
; CHECK: ; %bb.0:
; CHECK: %bb.0:
; CHECK-NEXT: xpacd x0
; CHECK-NEXT: ret
%tmp = call i64 @llvm.ptrauth.strip(i64 %arg, i32 2)
Expand All @@ -33,7 +33,7 @@ define i64 @test_strip_da(i64 %arg) {

define i64 @test_strip_db(i64 %arg) {
; CHECK-LABEL: test_strip_db:
; CHECK: ; %bb.0:
; CHECK: %bb.0:
; CHECK-NEXT: xpacd x0
; CHECK-NEXT: ret
%tmp = call i64 @llvm.ptrauth.strip(i64 %arg, i32 3)
Expand Down

0 comments on commit 746f572

Please sign in to comment.