1 ; RUN: llc -mtriple=aarch64 %s -o - | FileCheck %s
3 define void @f0() "patchable-function-entry"="0" "branch-target-enforcement"="true" {
5 ; CHECK-NEXT: .Lfunc_begin0:
9 ; CHECK-NOT: .section __patchable_function_entries
13 ;; -fpatchable-function-entry=1 -mbranch-protection=bti
14 ;; For M=0, place the label .Lpatch0 after the initial BTI.
15 define void @f1() "patchable-function-entry"="1" "branch-target-enforcement"="true" {
17 ; CHECK-NEXT: .Lfunc_begin1:
18 ; CHECK-NEXT: .cfi_startproc
19 ; CHECK-NEXT: // %bb.0:
20 ; CHECK-NEXT: hint #34
21 ; CHECK-NEXT: .Lpatch0:
24 ; CHECK: .section __patchable_function_entries,"awo",@progbits,f1{{$}}
25 ; CHECK-NEXT: .p2align 3
26 ; CHECK-NEXT: .xword .Lpatch0
30 ;; -fpatchable-function-entry=2,1 -mbranch-protection=bti
31 define void @f2_1() "patchable-function-entry"="1" "patchable-function-prefix"="1" "branch-target-enforcement"="true" {
32 ; CHECK-LABEL: .type f2_1,@function
36 ; CHECK-NEXT: .Lfunc_begin2:
37 ; CHECK-NEXT: .cfi_startproc
38 ; CHECK-NEXT: // %bb.0:
39 ; CHECK-NEXT: hint #34
43 ; CHECK-NEXT: .size f2_1, .Lfunc_end2-f2_1
44 ; CHECK: .section __patchable_function_entries,"awo",@progbits,f2_1{{$}}
45 ; CHECK-NEXT: .p2align 3
46 ; CHECK-NEXT: .xword .Ltmp0
50 ;; -fpatchable-function-entry=1 -mbranch-protection=bti
51 ;; We add BTI c even when the function has internal linkage
52 define internal void @f1i(i64 %v) "patchable-function-entry"="1" "branch-target-enforcement"="true" {
54 ; CHECK-NEXT: .Lfunc_begin3:
56 ; CHECK-NEXT: hint #34
57 ; CHECK-NEXT: .Lpatch1:
59 ;; Other basic blocks have BTI, but they don't affect our decision to not create .Lpatch0
60 ; CHECK: .LBB{{.+}} // %sw.bb1
61 ; CHECK-NEXT: hint #36
62 ; CHECK: .section __patchable_function_entries,"awo",@progbits,f1i{{$}}
63 ; CHECK-NEXT: .p2align 3
64 ; CHECK-NEXT: .xword .Lpatch1
66 switch i64 %v, label %sw.bb0 [
73 call void asm sideeffect "", ""()
76 call void asm sideeffect "", ""()
79 call void asm sideeffect "", ""()
82 call void asm sideeffect "", ""()
85 call void asm sideeffect "", ""()
89 ;; Test the interaction with -fsanitize=function.
90 ; CHECK: .type sanitize_function,@function
91 ; CHECK-NEXT: .Ltmp{{.*}}:
93 ; CHECK-NEXT: .word 3238382334 // 0xc105cafe
94 ; CHECK-NEXT: .word 42
95 ; CHECK-NEXT: sanitize_function:
96 ; CHECK-NEXT: .Lfunc_begin{{.*}}:
97 ; CHECK-NEXT: .cfi_startproc
98 ; CHECK-NEXT: // %bb.0:
99 ; CHECK-NEXT: hint #34
102 define void @sanitize_function(ptr noundef %x) "patchable-function-prefix"="1" "patchable-function-entry"="1" "branch-target-enforcement"="true" !func_sanitize !0 {
106 !0 = !{i32 3238382334, i32 42}