Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / metadata / covered.cpp
blob92abe4f5e8d8484d7644c582e03ff8a804fc26c0
1 // RUN: %clangxx %s -o %t && %t | FileCheck %s
2 // RUN: %clangxx %s -o %t -fexperimental-sanitize-metadata=covered && %t | FileCheck -check-prefix=CHECK-C %s
3 // RUN: %clangxx %s -o %t -fexperimental-sanitize-metadata=atomics && %t | FileCheck -check-prefix=CHECK-A %s
4 // RUN: %clangxx %s -o %t -fexperimental-sanitize-metadata=uar && %t | FileCheck -check-prefix=CHECK-U %s
5 // RUN: %clangxx %s -o %t -fexperimental-sanitize-metadata=covered,atomics && %t | FileCheck -check-prefix=CHECK-CA %s
6 // RUN: %clangxx %s -o %t -fexperimental-sanitize-metadata=covered,uar && %t | FileCheck -check-prefix=CHECK-CU %s
7 // RUN: %clangxx %s -o %t -fexperimental-sanitize-metadata=atomics,uar && %t | FileCheck -check-prefix=CHECK-AU %s
8 // RUN: %clangxx %s -o %t -fexperimental-sanitize-metadata=covered,atomics,uar && %t | FileCheck -check-prefix=CHECK-CAU %s
9 // RUN: %clangxx %s -o %t -mcmodel=large -fexperimental-sanitize-metadata=covered,atomics,uar && %t | FileCheck -check-prefix=CHECK-CAU %s
11 const int const_global = 42;
13 __attribute__((noinline, not_tail_called)) void escape(const volatile void *p) {
14 [[maybe_unused]] static const volatile void *sink;
15 sink = p;
18 // CHECK-NOT: metadata add
19 // CHECK: main
20 // CHECK-NOT: metadata del
22 // CHECK-C: empty: features=0
23 // CHECK-A-NOT: empty:
24 // CHECK-U-NOT: empty:
25 // CHECK-CA: empty: features=0
26 // CHECK-CU: empty: features=0
27 // CHECK-AU-NOT: empty:
28 // CHECK-CAU: empty: features=0
29 void empty() {}
31 // CHECK-C: normal: features=0
32 // CHECK-A: normal: features=1
33 // CHECK-U: normal: features=2
34 // CHECK-CA: normal: features=1
35 // CHECK-CU: normal: features=2
36 // CHECK-AU: normal: features=3
37 // CHECK-CAU:normal: features=3
38 void normal() {
39 int x;
40 escape(&x);
43 // CHECK-C: with_const_global: features=0
44 // CHECK-A-NOT: with_const_global:
45 // CHECK-U-NOT: with_const_global:
46 // CHECK-CA: with_const_global: features=0
47 // CHECK-CU: with_const_global: features=0
48 // CHECK-AU-NOT: with_const_global:
49 // CHECK-CAU: with_const_global: features=0
50 int with_const_global() { return *((const volatile int *)&const_global); }
52 // CHECK-C: with_atomic: features=0
53 // CHECK-A: with_atomic: features=1
54 // CHECK-U-NOT: with_atomic:
55 // CHECK-CA: with_atomic: features=1
56 // CHECK-CU: with_atomic: features=0
57 // CHECK-AU: with_atomic: features=1
58 // CHECK-CAU: with_atomic: features=1
59 int with_atomic(int *p) { return __atomic_load_n(p, __ATOMIC_RELAXED); }
61 // CHECK-C: with_atomic_escape: features=0
62 // CHECK-A: with_atomic_escape: features=1
63 // CHECK-U: with_atomic_escape: features=2
64 // CHECK-CA: with_atomic_escape: features=1
65 // CHECK-CU: with_atomic_escape: features=2
66 // CHECK-AU: with_atomic_escape: features=3
67 // CHECK-CAU: with_atomic_escape: features=3
68 int with_atomic_escape(int *p) {
69 escape(&p);
70 return __atomic_load_n(p, __ATOMIC_RELAXED);
73 // CHECK-C: with_atomic_escape_lots_of_args: features=0
74 // CHECK-A: with_atomic_escape_lots_of_args: features=1
75 // CHECK-U: with_atomic_escape_lots_of_args: features=6
76 // CHECK-CA: with_atomic_escape_lots_of_args: features=1
77 // CHECK-CU: with_atomic_escape_lots_of_args: features=6
78 // CHECK-AU: with_atomic_escape_lots_of_args: features=7
79 // CHECK-CAU: with_atomic_escape_lots_of_args: features=7
80 long with_atomic_escape_lots_of_args(int *p, long a0, long a1, long a2, long a3,
81 long a4, long a5, long a6) {
82 escape(&p);
83 return a0 + a1 + a2 + a3 + a4 + a5 + a6 +
84 __atomic_load_n(p, __ATOMIC_RELAXED);
87 // CHECK-C: ellipsis: features=0
88 // CHECK-A: ellipsis: features=1
89 // CHECK-U-NOT: ellipsis:
90 // CHECK-CA: ellipsis: features=1
91 // CHECK-CU: ellipsis: features=0
92 // CHECK-AU: ellipsis: features=1
93 // CHECK-CAU: ellipsis: features=1
94 void ellipsis(int *p, ...) {
95 escape(&p);
96 [[maybe_unused]] volatile int x;
97 x = 0;
100 // CHECK-C: ellipsis_with_atomic: features=0
101 // CHECK-A: ellipsis_with_atomic: features=1
102 // CHECK-U-NOT: ellipsis_with_atomic:
103 // CHECK-CA: ellipsis_with_atomic: features=1
104 // CHECK-CU: ellipsis_with_atomic: features=0
105 // CHECK-AU: ellipsis_with_atomic: features=1
106 // CHECK-CAU: ellipsis_with_atomic: features=1
107 int ellipsis_with_atomic(int *p, ...) {
108 escape(&p);
109 return __atomic_load_n(p, __ATOMIC_RELAXED);
112 #define FUNCTIONS \
113 FN(empty); \
114 FN(normal); \
115 FN(with_const_global); \
116 FN(with_atomic); \
117 FN(with_atomic_escape); \
118 FN(with_atomic_escape_lots_of_args); \
119 FN(ellipsis); \
120 FN(ellipsis_with_atomic); \
121 /**/
123 #include "common.h"