1+ ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
12; RUN: llc -mtriple=thumbv8.1m.main-arm-none-eabi < %s | FileCheck %s --check-prefix=BTI
23; RUN: llc -mtriple=thumbv8.1m.main-arm-none-eabi -mattr=+no-bti-at-return-twice < %s | \
34; RUN: FileCheck %s --check-prefix=NOBTI
2021
2122define i32 @foo (i32 %x ) "branch-target-enforcement" {
2223; BTI-LABEL: foo:
23- ; BTI: bl setjmp
24- ; BTI-NEXT: bti
24+ ; BTI: @ %bb.0: @ %entry
25+ ; BTI-NEXT: bti
26+ ; BTI-NEXT: .save {r4, lr}
27+ ; BTI-NEXT: push {r4, lr}
28+ ; BTI-NEXT: mov r4, r0
29+ ; BTI-NEXT: movw r0, :lower16:buf
30+ ; BTI-NEXT: movt r0, :upper16:buf
31+ ; BTI-NEXT: bl setjmp
32+ ; BTI-NEXT: bti
33+ ; BTI-NEXT: cmp r0, #0
34+ ; BTI-NEXT: itt ne
35+ ; BTI-NEXT: movne r0, #0
36+ ; BTI-NEXT: popne {r4, pc}
37+ ; BTI-NEXT: .LBB0_1: @ %if.else
38+ ; BTI-NEXT: mov r0, r4
39+ ; BTI-NEXT: bl bar
40+ ; BTI-NEXT: mov r0, r4
41+ ; BTI-NEXT: pop {r4, pc}
42+ ;
2543; NOBTI-LABEL: foo:
26- ; NOBTI: bl setjmp
27- ; NOBTI-NOT: bti
44+ ; NOBTI: @ %bb.0: @ %entry
45+ ; NOBTI-NEXT: bti
46+ ; NOBTI-NEXT: .save {r4, lr}
47+ ; NOBTI-NEXT: push {r4, lr}
48+ ; NOBTI-NEXT: mov r4, r0
49+ ; NOBTI-NEXT: movw r0, :lower16:buf
50+ ; NOBTI-NEXT: movt r0, :upper16:buf
51+ ; NOBTI-NEXT: bl setjmp
52+ ; NOBTI-NEXT: cmp r0, #0
53+ ; NOBTI-NEXT: itt ne
54+ ; NOBTI-NEXT: movne r0, #0
55+ ; NOBTI-NEXT: popne {r4, pc}
56+ ; NOBTI-NEXT: .LBB0_1: @ %if.else
57+ ; NOBTI-NEXT: mov r0, r4
58+ ; NOBTI-NEXT: bl bar
59+ ; NOBTI-NEXT: mov r0, r4
60+ ; NOBTI-NEXT: pop {r4, pc}
2861
2962entry:
3063 %call = call i32 @setjmp (ptr @buf ) #0
@@ -40,6 +73,41 @@ if.end: ; preds = %entry, %if.else
4073 ret i32 %x.addr.0
4174}
4275
76+ ;; Check that the BL to setjmp correctly clobbers LR
77+
78+ define i32 @baz () "branch-target-enforcement" {
79+ ; BTI-LABEL: baz:
80+ ; BTI: @ %bb.0: @ %entry
81+ ; BTI-NEXT: bti
82+ ; BTI-NEXT: .save {r7, lr}
83+ ; BTI-NEXT: push {r7, lr}
84+ ; BTI-NEXT: .pad #160
85+ ; BTI-NEXT: sub sp, #160
86+ ; BTI-NEXT: mov r0, sp
87+ ; BTI-NEXT: bl setjmp
88+ ; BTI-NEXT: bti
89+ ; BTI-NEXT: movs r0, #0
90+ ; BTI-NEXT: add sp, #160
91+ ; BTI-NEXT: pop {r7, pc}
92+ ;
93+ ; NOBTI-LABEL: baz:
94+ ; NOBTI: @ %bb.0: @ %entry
95+ ; NOBTI-NEXT: bti
96+ ; NOBTI-NEXT: .save {r7, lr}
97+ ; NOBTI-NEXT: push {r7, lr}
98+ ; NOBTI-NEXT: .pad #160
99+ ; NOBTI-NEXT: sub sp, #160
100+ ; NOBTI-NEXT: mov r0, sp
101+ ; NOBTI-NEXT: bl setjmp
102+ ; NOBTI-NEXT: movs r0, #0
103+ ; NOBTI-NEXT: add sp, #160
104+ ; NOBTI-NEXT: pop {r7, pc}
105+ entry:
106+ %outgoing_jb = alloca [20 x i64 ], align 8
107+ %call = call i32 @setjmp (ptr %outgoing_jb ) returns_twice
108+ ret i32 0
109+ }
110+
43111declare void @bar (i32 )
44112declare i32 @setjmp (ptr ) #0
45113
0 commit comments