1 // RUN: %clang_cc1 -triple %ms_abi_triple -fms-extensions -std=c++11 -emit-llvm -O2 -o - %s | FileCheck %s
2 // RUN: %clang_cc1 -triple x86_64-w64-windows-gnu -std=c++11 -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();
8 void (*func_ptr)() = &target_func;
9
10 // The "guard_nocf" attribute must be added.
nocf0()11 __declspec(guard(nocf)) void nocf0() {
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()20 __attribute__((guard(nocf))) void nocf0_gnu_style() {
21 (*func_ptr)();
22 }
23 // CHECK-LABEL: nocf0_gnu_style
24 // CHECK: call{{.*}}[[NOCF:#[0-9]+]]
25
26 // Test using the c++-style attribute.
27 // The "guard_nocf" attribute must be added.
nocf0_cxx_style()28 [[clang::guard(nocf)]] void nocf0_cxx_style() {
29 (*func_ptr)();
30 }
31 // CHECK-LABEL: nocf0_cxx_style
32 // CHECK: call{{.*}}[[NOCF:#[0-9]+]]
33
34 // The "guard_nocf" attribute must *not* be added.
cf0()35 void cf0() {
36 (*func_ptr)();
37 }
38 // CHECK-LABEL: cf0
39 // CHECK: call{{.*}}[[CF:#[0-9]+]]
40
41 // If the modifier is present on either the function declaration or definition,
42 // the "guard_nocf" attribute must be added.
43 __declspec(guard(nocf)) void nocf1();
nocf1()44 void nocf1() {
45 (*func_ptr)();
46 }
47 // CHECK-LABEL: nocf1
48 // CHECK: call{{.*}}[[NOCF:#[0-9]+]]
49
50 void nocf2();
nocf2()51 __declspec(guard(nocf)) void nocf2() {
52 (*func_ptr)();
53 }
54 // CHECK-LABEL: nocf2
55 // CHECK: call{{.*}}[[NOCF:#[0-9]+]]
56
57 // When inlining a function, the "guard_nocf" attribute on indirect calls must
58 // be preserved.
nocf3()59 void nocf3() {
60 nocf0();
61 }
62 // CHECK-LABEL: nocf3
63 // CHECK: call{{.*}}[[NOCF:#[0-9]+]]
64
65 // When inlining into a function marked as __declspec(guard(nocf)), the
66 // "guard_nocf" attribute must *not* be added to the inlined calls.
cf1()67 __declspec(guard(nocf)) void cf1() {
68 cf0();
69 }
70 // CHECK-LABEL: cf1
71 // CHECK: call{{.*}}[[CF:#[0-9]+]]
72
73 // When the __declspec(guard(nocf)) modifier is present on an override function,
74 // the "guard_nocf" attribute must be added.
75 struct Base {
76 virtual void nocf4();
77 };
78
79 struct Derived : Base {
nocf4Derived80 __declspec(guard(nocf)) void nocf4() override {
81 (*func_ptr)();
82 }
83 };
84 Derived d;
85 // CHECK-LABEL: nocf4
86 // CHECK: call{{.*}}[[NOCF:#[0-9]+]]
87
88 // When the modifier is not present on an override function, the "guard_nocf"
89 // attribute must *not* be added, even if the modifier is present on the virtual
90 // function.
91 struct Base1 {
92 __declspec(guard(nocf)) virtual void cf2();
93 };
94
95 struct Derived1 : Base1 {
cf2Derived196 void cf2() override {
97 (*func_ptr)();
98 }
99 };
100 Derived1 d1;
101 // CHECK-LABEL: cf2
102 // CHECK: call{{.*}}[[CF:#[0-9]+]]
103
104 // CHECK: attributes [[NOCF]] = { {{.*}}"guard_nocf"{{.*}} }
105 // CHECK-NOT: attributes [[CF]] = { {{.*}}"guard_nocf"{{.*}} }
106