1 ; RUN: llc < %s -mtriple=arm-pc-windows-msvc | FileCheck %s -check-prefixes=CHECK,MSVC
2 ; RUN: llc < %s -mtriple=arm-w64-windows-gnu | FileCheck %s -check-prefixes=CHECK,MINGW
3 ; Control Flow Guard is currently only available on Windows
5 ; Test that Control Flow Guard checks are correctly added when required.
8 declare i32 @target_func()
11 ; Test that Control Flow Guard checks are not added on calls with the "guard_nocf" attribute.
12 define i32 @func_guard_nocf() #0 {
14 %func_ptr = alloca ptr, align 8
15 store ptr @target_func, ptr %func_ptr, align 8
16 %0 = load ptr, ptr %func_ptr, align 8
17 %1 = call arm_aapcs_vfpcc i32 %0() #1
20 ; CHECK-LABEL: func_guard_nocf
21 ; CHECK: movw r0, :lower16:target_func
22 ; CHECK: movt r0, :upper16:target_func
23 ; CHECK-NOT: __guard_check_icall_fptr
26 attributes #0 = { "target-cpu"="cortex-a9" "target-features"="+armv7-a,+dsp,+fp16,+neon,+strict-align,+thumb-mode,+vfp3"}
27 attributes #1 = { "guard_nocf" }
30 ; Test that Control Flow Guard checks are added even at -O0.
31 define i32 @func_optnone_cf() #2 {
33 %func_ptr = alloca ptr, align 8
34 store ptr @target_func, ptr %func_ptr, align 8
35 %0 = load ptr, ptr %func_ptr, align 8
39 ; The call to __guard_check_icall_fptr should come immediately before the call to the target function.
40 ; CHECK-LABEL: func_optnone_cf
41 ; CHECK: movw r0, :lower16:target_func
42 ; CHECK: movt r0, :upper16:target_func
45 ; CHECK: movw r0, :lower16:__guard_check_icall_fptr
46 ; CHECK: movt r0, :upper16:__guard_check_icall_fptr
52 attributes #2 = { noinline optnone "target-cpu"="cortex-a9" "target-features"="+armv7-a,+dsp,+fp16,+neon,+strict-align,+thumb-mode,+vfp3"}
55 ; Test that Control Flow Guard checks are correctly added in optimized code (common case).
56 define i32 @func_cf() #0 {
58 %func_ptr = alloca ptr, align 8
59 store ptr @target_func, ptr %func_ptr, align 8
60 %0 = load ptr, ptr %func_ptr, align 8
64 ; The call to __guard_check_icall_fptr should come immediately before the call to the target function.
65 ; CHECK-LABEL: func_cf
66 ; CHECK: movw r0, :lower16:__guard_check_icall_fptr
67 ; CHECK: movt r0, :upper16:__guard_check_icall_fptr
69 ; CHECK: movw r4, :lower16:target_func
70 ; CHECK: movt r4, :upper16:target_func
77 ; Test that Control Flow Guard checks are correctly added on invoke instructions.
78 define i32 @func_cf_invoke() #0 personality ptr @h {
80 %0 = alloca i32, align 4
81 %func_ptr = alloca ptr, align 8
82 store ptr @target_func, ptr %func_ptr, align 8
83 %1 = load ptr, ptr %func_ptr, align 8
85 to label %invoke.cont unwind label %lpad
86 invoke.cont: ; preds = %entry
89 lpad: ; preds = %entry
90 %tmp = landingpad { ptr, i32 }
94 ; The call to __guard_check_icall_fptr should come immediately before the call to the target function.
95 ; CHECK-LABEL: func_cf_invoke
96 ; CHECK: movw r0, :lower16:__guard_check_icall_fptr
97 ; CHECK: movt r0, :upper16:__guard_check_icall_fptr
99 ; CHECK: movw r4, :lower16:target_func
100 ; CHECK: movt r4, :upper16:target_func
104 ; MINGW-NEXT: .Ltmp0:
106 ; CHECK: @ %common.ret
113 ; Test that longjmp targets have public labels and are included in the .gljmp section.
114 %struct._SETJMP_FLOAT128 = type { [2 x i64] }
115 @buf1 = internal global [16 x %struct._SETJMP_FLOAT128] zeroinitializer, align 16
117 define i32 @func_cf_setjmp() #0 {
118 %1 = alloca i32, align 4
119 %2 = alloca i32, align 4
120 store i32 0, ptr %1, align 4
121 store i32 -1, ptr %2, align 4
122 %3 = call ptr @llvm.frameaddress(i32 0)
123 %4 = call i32 @_setjmp(ptr @buf1, ptr %3) #3
125 ; CHECK-LABEL: func_cf_setjmp
127 ; CHECK-NEXT: $cfgsj_func_cf_setjmp0:
129 %5 = call ptr @llvm.frameaddress(i32 0)
130 %6 = call i32 @_setjmp(ptr @buf1, ptr %5) #3
133 ; CHECK-NEXT: $cfgsj_func_cf_setjmp1:
135 store i32 1, ptr %2, align 4
136 %7 = load i32, ptr %2, align 4
139 ; CHECK: .section .gljmp$y,"dr"
140 ; CHECK-NEXT: .symidx $cfgsj_func_cf_setjmp0
141 ; CHECK-NEXT: .symidx $cfgsj_func_cf_setjmp1
144 declare ptr @llvm.frameaddress(i32)
146 ; Function Attrs: returns_twice
147 declare dso_local i32 @_setjmp(ptr, ptr) #3
149 attributes #3 = { returns_twice }
152 !llvm.module.flags = !{!0}
153 !0 = !{i32 2, !"cfguard", i32 2}