1 // RUN: %clang_cc1 -triple %ms_abi_triple -fms-extensions -emit-llvm -O2 -o - %s | FileCheck %s
2 // RUN: %clang_cc1 -triple x86_64-w64-windows-gnu -emit-llvm -O2 -o - %s | FileCheck %s
3
4 // The x86_64-w64-windows-gnu version tests mingw target, which relies on
5 // __declspec(...) being defined as __attribute__((...)) by compiler built-in.
6
7 void target_func(void);
8 void (*func_ptr)(void) = &target_func;
9
10 // The "guard_nocf" attribute must be added.
nocf0(void)11 __declspec(guard(nocf)) void nocf0(void) {
12 (*func_ptr)();
13 }
14 // CHECK-LABEL: nocf0
15 // CHECK: call{{.*}}[[NOCF:#[0-9]+]]
16
17 // Explicitly test using the GNU-style attribute without relying on the
18 // __declspec define for mingw.
19 // The "guard_nocf" attribute must be added.
nocf0_gnu_style(void)20 __attribute__((guard(nocf))) void nocf0_gnu_style(void) {
21 (*func_ptr)();
22 }
23 // CHECK-LABEL: nocf0_gnu_style
24 // CHECK: call{{.*}}[[NOCF:#[0-9]+]]
25
26 // The "guard_nocf" attribute must *not* be added.
cf0(void)27 void cf0(void) {
28 (*func_ptr)();
29 }
30 // CHECK-LABEL: cf0
31 // CHECK: call{{.*}}[[CF:#[0-9]+]]
32
33 // If the modifier is present on either the function declaration or definition,
34 // the "guard_nocf" attribute must be added.
35 __declspec(guard(nocf)) void nocf1(void);
nocf1(void)36 void nocf1(void) {
37 (*func_ptr)();
38 }
39 // CHECK-LABEL: nocf1
40 // CHECK: call{{.*}}[[NOCF:#[0-9]+]]
41
42 void nocf2(void);
nocf2(void)43 __declspec(guard(nocf)) void nocf2(void) {
44 (*func_ptr)();
45 }
46 // CHECK-LABEL: nocf2
47 // CHECK: call{{.*}}[[NOCF:#[0-9]+]]
48
49 // When inlining a function, the "guard_nocf" attribute on indirect calls must
50 // be preserved.
nocf3(void)51 void nocf3(void) {
52 nocf0();
53 }
54 // CHECK-LABEL: nocf3
55 // CHECK: call{{.*}}[[NOCF:#[0-9]+]]
56
57 // When inlining into a function marked as __declspec(guard(nocf)), the
58 // "guard_nocf" attribute must *not* be added to the inlined calls.
cf1(void)59 __declspec(guard(nocf)) void cf1(void) {
60 cf0();
61 }
62 // CHECK-LABEL: cf1
63 // CHECK: call{{.*}}[[CF:#[0-9]+]]
64
65 // CHECK: attributes [[NOCF]] = { {{.*}}"guard_nocf"{{.*}} }
66 // CHECK-NOT: attributes [[CF]] = { {{.*}}"guard_nocf"{{.*}} }
67