[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / CodeGen / guard_nocf.c
blob0d66f7ff1bd98685b132384a197cb6529c860852
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
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(void);
8 void (*func_ptr)(void) = &target_func;
10 // The "guard_nocf" attribute must be added.
11 __declspec(guard(nocf)) void nocf0(void) {
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(void) {
21 (*func_ptr)();
23 // CHECK-LABEL: nocf0_gnu_style
24 // CHECK: call{{.*}}[[NOCF:#[0-9]+]]
26 // The "guard_nocf" attribute must *not* be added.
27 void cf0(void) {
28 (*func_ptr)();
30 // CHECK-LABEL: cf0
31 // CHECK: call{{.*}}[[CF:#[0-9]+]]
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);
36 void nocf1(void) {
37 (*func_ptr)();
39 // CHECK-LABEL: nocf1
40 // CHECK: call{{.*}}[[NOCF:#[0-9]+]]
42 void nocf2(void);
43 __declspec(guard(nocf)) void nocf2(void) {
44 (*func_ptr)();
46 // CHECK-LABEL: nocf2
47 // CHECK: call{{.*}}[[NOCF:#[0-9]+]]
49 // When inlining a function, the "guard_nocf" attribute on indirect calls must
50 // be preserved.
51 void nocf3(void) {
52 nocf0();
54 // CHECK-LABEL: nocf3
55 // CHECK: call{{.*}}[[NOCF:#[0-9]+]]
57 // When inlining into a function marked as __declspec(guard(nocf)), the
58 // "guard_nocf" attribute must *not* be added to the inlined calls.
59 __declspec(guard(nocf)) void cf1(void) {
60 cf0();
62 // CHECK-LABEL: cf1
63 // CHECK: call{{.*}}[[CF:#[0-9]+]]
65 // CHECK: attributes [[NOCF]] = { {{.*}}"guard_nocf"{{.*}} }
66 // CHECK-NOT: attributes [[CF]] = { {{.*}}"guard_nocf"{{.*}} }