1 ; RUN: llc < %s -mtriple=arm-pc-windows-msvc | FileCheck %s
2 ; Control Flow Guard is currently only available on Windows
4 ; Test that Control Flow Guard checks are correctly added when required.
7 declare i32 @target_func()
10 ; Test that Control Flow Guard checks are not added on calls with the "guard_nocf" attribute.
11 define i32 @func_guard_nocf() #0 {
13 %func_ptr = alloca i32 ()*, align 8
14 store i32 ()* @target_func, i32 ()** %func_ptr, align 8
15 %0 = load i32 ()*, i32 ()** %func_ptr, align 8
16 %1 = call arm_aapcs_vfpcc i32 %0() #1
19 ; CHECK-LABEL: func_guard_nocf
20 ; CHECK: movw r0, :lower16:target_func
21 ; CHECK: movt r0, :upper16:target_func
22 ; CHECK-NOT: __guard_check_icall_fptr
25 attributes #0 = { "target-cpu"="cortex-a9" "target-features"="+armv7-a,+dsp,+fp16,+neon,+strict-align,+thumb-mode,+vfp3"}
26 attributes #1 = { "guard_nocf" }
29 ; Test that Control Flow Guard checks are added even at -O0.
30 define i32 @func_optnone_cf() #2 {
32 %func_ptr = alloca i32 ()*, align 8
33 store i32 ()* @target_func, i32 ()** %func_ptr, align 8
34 %0 = load i32 ()*, i32 ()** %func_ptr, align 8
38 ; The call to __guard_check_icall_fptr should come immediately before the call to the target function.
39 ; CHECK-LABEL: func_optnone_cf
40 ; CHECK: movw r0, :lower16:target_func
41 ; CHECK: movt r0, :upper16:target_func
44 ; CHECK: movw r0, :lower16:__guard_check_icall_fptr
45 ; CHECK: movt r0, :upper16:__guard_check_icall_fptr
51 attributes #2 = { noinline optnone "target-cpu"="cortex-a9" "target-features"="+armv7-a,+dsp,+fp16,+neon,+strict-align,+thumb-mode,+vfp3"}
54 ; Test that Control Flow Guard checks are correctly added in optimized code (common case).
55 define i32 @func_cf() #0 {
57 %func_ptr = alloca i32 ()*, align 8
58 store i32 ()* @target_func, i32 ()** %func_ptr, align 8
59 %0 = load i32 ()*, i32 ()** %func_ptr, align 8
63 ; The call to __guard_check_icall_fptr should come immediately before the call to the target function.
64 ; CHECK-LABEL: func_cf
65 ; CHECK: movw r0, :lower16:__guard_check_icall_fptr
66 ; CHECK: movt r0, :upper16:__guard_check_icall_fptr
68 ; CHECK: movw r4, :lower16:target_func
69 ; CHECK: movt r4, :upper16:target_func
76 ; Test that Control Flow Guard checks are correctly added on invoke instructions.
77 define i32 @func_cf_invoke() #0 personality i8* bitcast (void ()* @h to i8*) {
79 %0 = alloca i32, align 4
80 %func_ptr = alloca i32 ()*, align 8
81 store i32 ()* @target_func, i32 ()** %func_ptr, align 8
82 %1 = load i32 ()*, i32 ()** %func_ptr, align 8
84 to label %invoke.cont unwind label %lpad
85 invoke.cont: ; preds = %entry
88 lpad: ; preds = %entry
89 %tmp = landingpad { i8*, i32 }
93 ; The call to __guard_check_icall_fptr should come immediately before the call to the target function.
94 ; CHECK-LABEL: func_cf_invoke
95 ; CHECK: movw r0, :lower16:__guard_check_icall_fptr
96 ; CHECK: movt r0, :upper16:__guard_check_icall_fptr
98 ; CHECK: movw r4, :lower16:target_func
99 ; CHECK: movt r4, :upper16:target_func
102 ; CHECK-NEXT: $Mtmp0:
104 ; CHECK: ; %common.ret
111 ; Test that longjmp targets have public labels and are included in the .gljmp section.
112 %struct._SETJMP_FLOAT128 = type { [2 x i64] }
113 @buf1 = internal global [16 x %struct._SETJMP_FLOAT128] zeroinitializer, align 16
115 define i32 @func_cf_setjmp() #0 {
116 %1 = alloca i32, align 4
117 %2 = alloca i32, align 4
118 store i32 0, i32* %1, align 4
119 store i32 -1, i32* %2, align 4
120 %3 = call i8* @llvm.frameaddress(i32 0)
121 %4 = call i32 @_setjmp(i8* bitcast ([16 x %struct._SETJMP_FLOAT128]* @buf1 to i8*), i8* %3) #3
123 ; CHECK-LABEL: func_cf_setjmp
125 ; CHECK-NEXT: $cfgsj_func_cf_setjmp0:
127 %5 = call i8* @llvm.frameaddress(i32 0)
128 %6 = call i32 @_setjmp(i8* bitcast ([16 x %struct._SETJMP_FLOAT128]* @buf1 to i8*), i8* %5) #3
131 ; CHECK-NEXT: $cfgsj_func_cf_setjmp1:
133 store i32 1, i32* %2, align 4
134 %7 = load i32, i32* %2, align 4
137 ; CHECK: .section .gljmp$y,"dr"
138 ; CHECK-NEXT: .symidx $cfgsj_func_cf_setjmp0
139 ; CHECK-NEXT: .symidx $cfgsj_func_cf_setjmp1
142 declare i8* @llvm.frameaddress(i32)
144 ; Function Attrs: returns_twice
145 declare dso_local i32 @_setjmp(i8*, i8*) #3
147 attributes #3 = { returns_twice }
150 !llvm.module.flags = !{!0}
151 !0 = !{i32 2, !"cfguard", i32 2}