llvm-project/llvm/test/CodeGen/ARM/pacbti-indirect-tail-calls-function-flags.ll
Eleanor Bonnici c12bc57e23
Do not use R12 for indirect tail calls with PACBTI (#82661)
When compiling for thumbv8.1m with +pacbti and making an indirect tail
call, the compiler was free to put the function pointer into R12.

This is incorrect because R12 is restored to contain authentication code
for the caller's return address.

This patch excludes R12 from the set of registers the compiler can put
the function pointer in.

Fixes https://github.com/llvm/llvm-project/issues/75998
2024-04-30 15:29:07 +01:00

38 lines
1014 B
LLVM

; RUN: llc -mtriple=thumbv8.1m.main-none-none-eabi -mattr=+pacbti< %s | FileCheck %s
target datalayout = "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64"
target triple = "thumbv8.1m.main-m.main-unknown"
; When PACBTI is enabled, indirect tail-calls must not use R12 that is used
; to store authentication code.
define void @pacbti_disabled(ptr %p) "sign-return-address"="none" {
entry:
tail call void %p()
; CHECK: bx {{r0|r1|r2|r3|r12}}
ret void
}
define void @pacbti_enabled(ptr %p) "sign-return-address"="all" {
entry:
tail call void %p()
; CHECK: bx {{r0|r1|r2|r3}}
ret void
}
define void @pacbti_disabled_force_r12(ptr %p) "sign-return-address"="none" {
entry:
%p_r12 = tail call ptr asm "", "={r12},{r12},~{lr}"(ptr %p)
tail call void %p_r12()
; CHECK: bx r12
ret void
}
define void @pacbti_enabled_force_r12(ptr %p) "sign-return-address"="all" {
entry:
%p_r12 = tail call ptr asm "", "={r12},{r12},~{lr}"(ptr %p)
tail call void %p_r12()
; CHECK: bx {{r0|r1|r2|r3}}
ret void
}