1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
3 ; RUN: llc -mtriple arm64e-apple-darwin \
4 ; RUN: -aarch64-enable-collect-loh=false \
5 ; RUN: -aarch64-min-jump-table-entries=1 -aarch64-enable-atomic-cfg-tidy=0 \
6 ; RUN: -o - %s | FileCheck %s --check-prefix=MACHO
8 ; RUN: llc -mtriple arm64e-apple-darwin \
10 ; RUN: -aarch64-enable-collect-loh=false \
11 ; RUN: -aarch64-min-jump-table-entries=1 -aarch64-enable-atomic-cfg-tidy=0 \
12 ; RUN: -o - %s | FileCheck %s --check-prefix=MACHO
14 ; RUN: llc -mtriple arm64e-apple-darwin \
15 ; RUN: -global-isel -global-isel-abort=1 -verify-machineinstrs \
16 ; RUN: -aarch64-enable-collect-loh=false \
17 ; RUN: -aarch64-min-jump-table-entries=1 -aarch64-enable-atomic-cfg-tidy=0 \
18 ; RUN: -o - %s | FileCheck %s --check-prefix=MACHO
20 ; RUN: llc -mtriple aarch64-elf -mattr=+pauth \
21 ; RUN: -aarch64-min-jump-table-entries=1 -aarch64-enable-atomic-cfg-tidy=0 \
22 ; RUN: -o - %s | FileCheck %s --check-prefix=ELF
24 ; RUN: llc -mtriple aarch64-elf -mattr=+pauth \
26 ; RUN: -aarch64-min-jump-table-entries=1 -aarch64-enable-atomic-cfg-tidy=0 \
27 ; RUN: -o - %s | FileCheck %s --check-prefix=ELF
29 ; RUN: llc -mtriple aarch64-elf -mattr=+pauth \
30 ; RUN: -global-isel -global-isel-abort=1 -verify-machineinstrs \
31 ; RUN: -aarch64-min-jump-table-entries=1 -aarch64-enable-atomic-cfg-tidy=0 \
32 ; RUN: -o - %s | FileCheck %s --check-prefix=ELF
34 ;; The discriminator is the same for all blockaddresses in the function.
35 ;; ptrauth_string_discriminator("test_indirectbr blockaddress") == 34947
37 define i32 @test_indirectbr() #0 {
38 ; MACHO-LABEL: test_indirectbr:
39 ; MACHO: ; %bb.0: ; %entry
40 ; MACHO-NEXT: stp x29, x30, [sp, #-16]! ; 16-byte Folded Spill
41 ; MACHO-NEXT: adrp x16, Ltmp0@PAGE
42 ; MACHO-NEXT: add x16, x16, Ltmp0@PAGEOFF
43 ; MACHO-NEXT: mov x17, #34947 ; =0x8883
44 ; MACHO-NEXT: pacia x16, x17
45 ; MACHO-NEXT: mov x0, x16
46 ; MACHO-NEXT: adrp x16, Ltmp1@PAGE
47 ; MACHO-NEXT: add x16, x16, Ltmp1@PAGEOFF
48 ; MACHO-NEXT: mov x17, #34947 ; =0x8883
49 ; MACHO-NEXT: pacia x16, x17
50 ; MACHO-NEXT: mov x1, x16
51 ; MACHO-NEXT: bl _dummy_choose
52 ; MACHO-NEXT: mov x17, #34947 ; =0x8883
53 ; MACHO-NEXT: braa x0, x17
54 ; MACHO-NEXT: Ltmp0: ; Block address taken
55 ; MACHO-NEXT: LBB0_1: ; %bb1
56 ; MACHO-NEXT: mov w0, #1 ; =0x1
57 ; MACHO-NEXT: ldp x29, x30, [sp], #16 ; 16-byte Folded Reload
59 ; MACHO-NEXT: Ltmp1: ; Block address taken
60 ; MACHO-NEXT: LBB0_2: ; %bb2
61 ; MACHO-NEXT: mov w0, #2 ; =0x2
62 ; MACHO-NEXT: ldp x29, x30, [sp], #16 ; 16-byte Folded Reload
65 ; ELF-LABEL: test_indirectbr:
66 ; ELF: // %bb.0: // %entry
67 ; ELF-NEXT: str x30, [sp, #-16]! // 8-byte Folded Spill
68 ; ELF-NEXT: adrp x16, .Ltmp0
69 ; ELF-NEXT: add x16, x16, :lo12:.Ltmp0
70 ; ELF-NEXT: mov x17, #34947 // =0x8883
71 ; ELF-NEXT: pacia x16, x17
72 ; ELF-NEXT: mov x0, x16
73 ; ELF-NEXT: adrp x16, .Ltmp1
74 ; ELF-NEXT: add x16, x16, :lo12:.Ltmp1
75 ; ELF-NEXT: mov x17, #34947 // =0x8883
76 ; ELF-NEXT: pacia x16, x17
77 ; ELF-NEXT: mov x1, x16
78 ; ELF-NEXT: bl dummy_choose
79 ; ELF-NEXT: mov x17, #34947 // =0x8883
80 ; ELF-NEXT: braa x0, x17
81 ; ELF-NEXT: .Ltmp0: // Block address taken
82 ; ELF-NEXT: .LBB0_1: // %bb1
83 ; ELF-NEXT: mov w0, #1 // =0x1
84 ; ELF-NEXT: ldr x30, [sp], #16 // 8-byte Folded Reload
86 ; ELF-NEXT: .Ltmp1: // Block address taken
87 ; ELF-NEXT: .LBB0_2: // %bb2
88 ; ELF-NEXT: mov w0, #2 // =0x2
89 ; ELF-NEXT: ldr x30, [sp], #16 // 8-byte Folded Reload
92 %tmp0 = call ptr @dummy_choose(ptr blockaddress(@test_indirectbr, %bb1), ptr blockaddress(@test_indirectbr, %bb2))
93 indirectbr ptr %tmp0, [label %bb1, label %bb2]
102 define ptr @test_indirectbr_other_function() #0 {
103 ; MACHO-LABEL: test_indirectbr_other_function:
105 ; MACHO-NEXT: adrp x16, Ltmp0@PAGE
106 ; MACHO-NEXT: add x16, x16, Ltmp0@PAGEOFF
107 ; MACHO-NEXT: mov x17, #34947 ; =0x8883
108 ; MACHO-NEXT: pacia x16, x17
109 ; MACHO-NEXT: mov x0, x16
112 ; ELF-LABEL: test_indirectbr_other_function:
114 ; ELF-NEXT: adrp x16, .Ltmp0
115 ; ELF-NEXT: add x16, x16, :lo12:.Ltmp0
116 ; ELF-NEXT: mov x17, #34947 // =0x8883
117 ; ELF-NEXT: pacia x16, x17
118 ; ELF-NEXT: mov x0, x16
120 ret ptr blockaddress(@test_indirectbr, %bb1)
123 ;; Test another function to compare the discriminator.
124 ;; ptrauth_string_discriminator("test_indirectbr_2 blockaddress") == 40224
126 define i32 @test_indirectbr_2() #0 {
127 ; MACHO-LABEL: test_indirectbr_2:
128 ; MACHO: ; %bb.0: ; %entry
129 ; MACHO-NEXT: stp x29, x30, [sp, #-16]! ; 16-byte Folded Spill
130 ; MACHO-NEXT: adrp x16, Ltmp2@PAGE
131 ; MACHO-NEXT: add x16, x16, Ltmp2@PAGEOFF
132 ; MACHO-NEXT: mov x17, #40224 ; =0x9d20
133 ; MACHO-NEXT: pacia x16, x17
134 ; MACHO-NEXT: mov x0, x16
135 ; MACHO-NEXT: adrp x16, Ltmp3@PAGE
136 ; MACHO-NEXT: add x16, x16, Ltmp3@PAGEOFF
137 ; MACHO-NEXT: mov x17, #40224 ; =0x9d20
138 ; MACHO-NEXT: pacia x16, x17
139 ; MACHO-NEXT: mov x1, x16
140 ; MACHO-NEXT: bl _dummy_choose
141 ; MACHO-NEXT: mov x17, #40224 ; =0x9d20
142 ; MACHO-NEXT: braa x0, x17
143 ; MACHO-NEXT: Ltmp2: ; Block address taken
144 ; MACHO-NEXT: LBB2_1: ; %bb1
145 ; MACHO-NEXT: mov w0, #1 ; =0x1
146 ; MACHO-NEXT: ldp x29, x30, [sp], #16 ; 16-byte Folded Reload
148 ; MACHO-NEXT: Ltmp3: ; Block address taken
149 ; MACHO-NEXT: LBB2_2: ; %bb2
150 ; MACHO-NEXT: mov w0, #2 ; =0x2
151 ; MACHO-NEXT: ldp x29, x30, [sp], #16 ; 16-byte Folded Reload
154 ; ELF-LABEL: test_indirectbr_2:
155 ; ELF: // %bb.0: // %entry
156 ; ELF-NEXT: str x30, [sp, #-16]! // 8-byte Folded Spill
157 ; ELF-NEXT: adrp x16, .Ltmp2
158 ; ELF-NEXT: add x16, x16, :lo12:.Ltmp2
159 ; ELF-NEXT: mov x17, #40224 // =0x9d20
160 ; ELF-NEXT: pacia x16, x17
161 ; ELF-NEXT: mov x0, x16
162 ; ELF-NEXT: adrp x16, .Ltmp3
163 ; ELF-NEXT: add x16, x16, :lo12:.Ltmp3
164 ; ELF-NEXT: mov x17, #40224 // =0x9d20
165 ; ELF-NEXT: pacia x16, x17
166 ; ELF-NEXT: mov x1, x16
167 ; ELF-NEXT: bl dummy_choose
168 ; ELF-NEXT: mov x17, #40224 // =0x9d20
169 ; ELF-NEXT: braa x0, x17
170 ; ELF-NEXT: .Ltmp2: // Block address taken
171 ; ELF-NEXT: .LBB2_1: // %bb1
172 ; ELF-NEXT: mov w0, #1 // =0x1
173 ; ELF-NEXT: ldr x30, [sp], #16 // 8-byte Folded Reload
175 ; ELF-NEXT: .Ltmp3: // Block address taken
176 ; ELF-NEXT: .LBB2_2: // %bb2
177 ; ELF-NEXT: mov w0, #2 // =0x2
178 ; ELF-NEXT: ldr x30, [sp], #16 // 8-byte Folded Reload
181 %tmp0 = call ptr @dummy_choose(ptr blockaddress(@test_indirectbr_2, %bb1), ptr blockaddress(@test_indirectbr_2, %bb2))
182 indirectbr ptr %tmp0, [label %bb1, label %bb2]
191 ;; Check we don't interfere with jump-table BRIND lowering.
193 ; MACHO-LABEL: test_jumptable:
194 ; MACHO: adrp x9, LJTI3_0@PAGE
195 ; MACHO-NEXT: add x9, x9, LJTI3_0@PAGEOFF
196 ; MACHO-NEXT: adr x10, LBB3_2
197 ; MACHO-NEXT: ldrb w11, [x9, x8]
198 ; MACHO-NEXT: add x10, x10, x11, lsl #2
201 ; ELF-LABEL: test_jumptable:
202 ; ELF: adrp x9, .LJTI3_0
203 ; ELF-NEXT: add x9, x9, :lo12:.LJTI3_0
204 ; ELF-NEXT: adr x10, .LBB3_2
205 ; ELF-NEXT: ldrb w11, [x9, x8]
206 ; ELF-NEXT: add x10, x10, x11, lsl #2
208 define i32 @test_jumptable(i32 %in) #0 {
209 switch i32 %in, label %def [
224 ; MACHO-LABEL: .globl _test_indirectbr_array
225 ; MACHO-NEXT: .p2align 4
226 ; MACHO-NEXT: _test_indirectbr_array:
227 ; MACHO-NEXT: .quad Ltmp0@AUTH(ia,34947)
228 ; MACHO-NEXT: .quad Ltmp1@AUTH(ia,34947)
229 ; MACHO-NEXT: .quad Ltmp2@AUTH(ia,40224)
230 ; MACHO-NEXT: .quad Ltmp3@AUTH(ia,40224)
232 ; ELF-LABEL: .globl test_indirectbr_array
233 ; ELF-NEXT: .p2align 4, 0x0
234 ; ELF-NEXT: test_indirectbr_array:
235 ; ELF-NEXT: .xword .Ltmp0@AUTH(ia,34947)
236 ; ELF-NEXT: .xword .Ltmp1@AUTH(ia,34947)
237 ; ELF-NEXT: .xword .Ltmp2@AUTH(ia,40224)
238 ; ELF-NEXT: .xword .Ltmp3@AUTH(ia,40224)
239 ; ELF-NEXT: .size test_indirectbr_array, 32
241 @test_indirectbr_array = constant [4 x ptr] [
242 ptr blockaddress(@test_indirectbr, %bb1), ptr blockaddress(@test_indirectbr, %bb2),
243 ptr blockaddress(@test_indirectbr_2, %bb1), ptr blockaddress(@test_indirectbr_2, %bb2)
246 declare ptr @dummy_choose(ptr, ptr)
248 attributes #0 = { "ptrauth-indirect-gotos" nounwind }