|
| 1 | +; RUN: llc -mtriple aarch64-linux-pauthtest -o - %s \ |
| 2 | +; RUN: -aarch64-authenticated-lr-check-method=xpac-hint \ |
| 3 | +; RUN: -stop-before=aarch64-ptrauth \ |
| 4 | +; RUN: | FileCheck --check-prefix=MIR %s |
| 5 | + |
| 6 | +; RUN: llc -mtriple aarch64-linux-pauthtest -o - %s \ |
| 7 | +; RUN: -aarch64-authenticated-lr-check-method=xpac-hint \ |
| 8 | +; RUN: | FileCheck --check-prefix=ASM %s |
| 9 | + |
| 10 | +target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32" |
| 11 | + |
| 12 | +; Test that expansion of AUTH_TCRETURN does not crash due to unavailability of |
| 13 | +; neither x16 nor x17 as a scratch register. |
| 14 | +define i32 @test_scratch_reg_nobti(ptr %callee, ptr %addr) #0 { |
| 15 | +entry: |
| 16 | + ; Force spilling of LR |
| 17 | + tail call void asm sideeffect "", "~{lr}"() |
| 18 | + ; Clobber x0-x15 and x18-x29 |
| 19 | + tail call void asm sideeffect "", "~{x0},~{x1},~{x2},~{x3},~{x4},~{x5},~{x6},~{x7},~{x8},~{x9},~{x10},~{x11},~{x12},~{x13},~{x14},~{x15}"() |
| 20 | + tail call void asm sideeffect "", "~{x18},~{x19},~{x20},~{x21},~{x22},~{x23},~{x24},~{x25},~{x26},~{x27},~{x28},~{fp}"() |
| 21 | + %addr.i = ptrtoint ptr %addr to i64 |
| 22 | + %call = tail call i32 %callee() #1 [ "ptrauth"(i32 0, i64 %addr.i) ] |
| 23 | + ret i32 %call |
| 24 | +} |
| 25 | +; MIR-LABEL: name: test_scratch_reg_nobti |
| 26 | +; MIR: AUTH_TCRETURN{{ }} |
| 27 | +; |
| 28 | +; ASM-LABEL: @test_scratch_reg_nobti |
| 29 | +; ASM: autibsp |
| 30 | +; ASM-NEXT: eor x17, x30, x30, lsl #1 |
| 31 | +; ASM-NEXT: tbz x17, #62, .Lauth_success_0 |
| 32 | +; ASM-NEXT: brk #0xc471 |
| 33 | +; ASM-NEXT: .Lauth_success_0: |
| 34 | +; ASM-NEXT: braa x0, x16 |
| 35 | + |
| 36 | +; The same for AUTH_TCRETURN_BTI. |
| 37 | +define i32 @test_scratch_reg_bti(ptr %callee, ptr %addr) "branch-target-enforcement" #0 { |
| 38 | +entry: |
| 39 | + ; Force spilling of LR |
| 40 | + tail call void asm sideeffect "", "~{lr}"() |
| 41 | + ; Clobber x0-x15 and x18-x29 |
| 42 | + tail call void asm sideeffect "", "~{x0},~{x1},~{x2},~{x3},~{x4},~{x5},~{x6},~{x7},~{x8},~{x9},~{x10},~{x11},~{x12},~{x13},~{x14},~{x15}"() |
| 43 | + tail call void asm sideeffect "", "~{x18},~{x19},~{x20},~{x21},~{x22},~{x23},~{x24},~{x25},~{x26},~{x27},~{x28},~{fp}"() |
| 44 | + %addr.i = ptrtoint ptr %addr to i64 |
| 45 | + %call = tail call i32 %callee() #1 [ "ptrauth"(i32 0, i64 %addr.i) ] |
| 46 | + ret i32 %call |
| 47 | +} |
| 48 | +; MIR-LABEL: name: test_scratch_reg_bti |
| 49 | +; MIR: AUTH_TCRETURN_BTI |
| 50 | +; |
| 51 | +; ASM-LABEL: @test_scratch_reg_bti |
| 52 | +; ASM: autibsp |
| 53 | +; ASM-NEXT: eor x17, x30, x30, lsl #1 |
| 54 | +; ASM-NEXT: tbz x17, #62, .Lauth_success_1 |
| 55 | +; ASM-NEXT: brk #0xc471 |
| 56 | +; ASM-NEXT: .Lauth_success_1: |
| 57 | +; ASM-NEXT: braa x16, x0 |
| 58 | + |
| 59 | +attributes #0 = { nounwind "ptrauth-auth-traps" "ptrauth-calls" "ptrauth-returns" "target-features"="+pauth" } |
0 commit comments