[Clang] replace 'bitfield' with 'bit-field' for consistency (#117881)
[llvm-project.git] / clang / test / CodeGenCXX / guard_nocf.cpp
blobad434b73499a529d28a67b2c9ef41520e948d976
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
4 // The x86_64-w64-windows-gnu version tests mingw target, which relies on
5 // __declspec(...) being defined as __attribute__((...)) by compiler built-in.
7 void target_func();
8 void (*func_ptr)() = &target_func;
10 // The "guard_nocf" attribute must be added.
11 __declspec(guard(nocf)) void nocf0() {
12 (*func_ptr)();
14 // CHECK-LABEL: nocf0
15 // CHECK: call{{.*}}[[NOCF:#[0-9]+]]
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.
20 __attribute__((guard(nocf))) void nocf0_gnu_style() {
21 (*func_ptr)();
23 // CHECK-LABEL: nocf0_gnu_style
24 // CHECK: call{{.*}}[[NOCF:#[0-9]+]]
26 // Test using the c++-style attribute.
27 // The "guard_nocf" attribute must be added.
28 [[clang::guard(nocf)]] void nocf0_cxx_style() {
29 (*func_ptr)();
31 // CHECK-LABEL: nocf0_cxx_style
32 // CHECK: call{{.*}}[[NOCF:#[0-9]+]]
34 // The "guard_nocf" attribute must *not* be added.
35 void cf0() {
36 (*func_ptr)();
38 // CHECK-LABEL: cf0
39 // CHECK: call{{.*}}[[CF:#[0-9]+]]
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();
44 void nocf1() {
45 (*func_ptr)();
47 // CHECK-LABEL: nocf1
48 // CHECK: call{{.*}}[[NOCF:#[0-9]+]]
50 void nocf2();
51 __declspec(guard(nocf)) void nocf2() {
52 (*func_ptr)();
54 // CHECK-LABEL: nocf2
55 // CHECK: call{{.*}}[[NOCF:#[0-9]+]]
57 // When inlining a function, the "guard_nocf" attribute on indirect calls must
58 // be preserved.
59 void nocf3() {
60 nocf0();
62 // CHECK-LABEL: nocf3
63 // CHECK: call{{.*}}[[NOCF:#[0-9]+]]
65 // When inlining into a function marked as __declspec(guard(nocf)), the
66 // "guard_nocf" attribute must *not* be added to the inlined calls.
67 __declspec(guard(nocf)) void cf1() {
68 cf0();
70 // CHECK-LABEL: cf1
71 // CHECK: call{{.*}}[[CF:#[0-9]+]]
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();
79 struct Derived : Base {
80 __declspec(guard(nocf)) void nocf4() override {
81 (*func_ptr)();
84 Derived d;
85 // CHECK-LABEL: nocf4
86 // CHECK: call{{.*}}[[NOCF:#[0-9]+]]
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();
95 struct Derived1 : Base1 {
96 void cf2() override {
97 (*func_ptr)();
100 Derived1 d1;
101 // CHECK-LABEL: cf2
102 // CHECK: call{{.*}}[[CF:#[0-9]+]]
104 // CHECK: attributes [[NOCF]] = { {{.*}}"guard_nocf"{{.*}} }
105 // CHECK-NOT: attributes [[CF]] = { {{.*}}"guard_nocf"{{.*}} }