Revert "[llvm] Improve llvm.objectsize computation by computing GEP, alloca and mallo...
[llvm-project.git] / clang / test / CodeGen / sanitize-coverage.c
blobcb1ed939d4a934a1992caab95691d61d7f98d605
1 // RUN: %clang %s -target x86_64-unknown-linux-gnu -emit-llvm -S -fsanitize-coverage=trace-pc,trace-cmp -o - | FileCheck %s --check-prefixes=CHECK
2 // RUN: %clang %s -target x86_64-unknown-linux-gnu -emit-llvm -S -fsanitize=address -fsanitize-coverage=trace-pc,trace-cmp -o - | FileCheck %s --check-prefixes=CHECK,ASAN
3 // RUN: %clang %s -target x86_64-unknown-linux-gnu -emit-llvm -S -fsanitize=bounds -fsanitize-coverage=trace-pc,trace-cmp -o - | FileCheck %s --check-prefixes=CHECK,BOUNDS
4 // RUN: %clang %s -target x86_64-unknown-linux-gnu -emit-llvm -S -fsanitize=memory -fsanitize-coverage=trace-pc,trace-cmp -o - | FileCheck %s --check-prefixes=CHECK,MSAN
5 // RUN: %clang %s -target x86_64-unknown-linux-gnu -emit-llvm -S -fsanitize=thread -fsanitize-coverage=trace-pc,trace-cmp -o - | FileCheck %s --check-prefixes=CHECK,TSAN
6 // RUN: %clang %s -target x86_64-unknown-linux-gnu -emit-llvm -S -fsanitize=undefined -fsanitize-coverage=trace-pc,trace-cmp -o - | FileCheck %s --check-prefixes=CHECK,UBSAN
7 // RUN: %clang %s -target x86_64-unknown-linux-gnu -emit-llvm -S -fsanitize=kcfi -fsanitize-coverage=trace-pc,trace-cmp -o - | FileCheck %s --check-prefixes=CHECK,KCFI
9 int x[10];
10 extern void (*f)(void);
12 // CHECK-LABEL: define dso_local void @foo(
13 void foo(int n) {
14 // CHECK-DAG: call void @__sanitizer_cov_trace_pc
15 // CHECK-DAG: call void @__sanitizer_cov_trace_const_cmp
16 // ASAN-DAG: call void @__asan_report_store
17 // MSAN-DAG: call void @__msan_warning
18 // BOUNDS-DAG: call void @__ubsan_handle_out_of_bounds
19 // TSAN-DAG: call void @__tsan_func_entry
20 // UBSAN-DAG: call void @__ubsan_handle
21 if (n)
22 x[n] = 42;
23 // KCFI-DAG: call void %[[#]]() [ "kcfi"(i32 {{.*}}) ]
24 f();
27 static inline __attribute__((__always_inline__)) void always_inlined_fn(int n) {
28 if (n)
29 x[n] = 42;
31 // CHECK-LABEL: define dso_local void @test_always_inline(
32 void test_always_inline(int n) {
33 // CHECK-DAG: call void @__sanitizer_cov_trace_pc
34 // CHECK-DAG: call void @__sanitizer_cov_trace_const_cmp
35 always_inlined_fn(n);
38 // CHECK-LABEL: define dso_local void @test_no_sanitize_coverage(
39 __attribute__((no_sanitize("coverage"))) void test_no_sanitize_coverage(int n) {
40 // CHECK-NOT: call void @__sanitizer_cov_trace_pc
41 // CHECK-NOT: call void @__sanitizer_cov_trace_const_cmp
42 // ASAN-DAG: call void @__asan_report_store
43 // MSAN-DAG: call void @__msan_warning
44 // BOUNDS-DAG: call void @__ubsan_handle_out_of_bounds
45 // TSAN-DAG: call void @__tsan_func_entry
46 // UBSAN-DAG: call void @__ubsan_handle
47 if (n)
48 x[n] = 42;
49 // KCFI-DAG: call void %[[#]]() [ "kcfi"(i32 {{.*}}) ]
50 f();
54 // CHECK-LABEL: define dso_local void @test_no_sanitize_combined(
55 __attribute__((no_sanitize("address", "memory", "thread", "bounds", "undefined", "coverage")))
56 void test_no_sanitize_combined(int n) {
57 // CHECK-NOT: call void @__sanitizer_cov_trace_pc
58 // CHECK-NOT: call void @__sanitizer_cov_trace_const_cmp
59 // ASAN-NOT: call void @__asan_report_store
60 // MSAN-NOT: call void @__msan_warning
61 // BOUNDS-NOT: call void @__ubsan_handle_out_of_bounds
62 // BOUNDS-NOT: call void @llvm.trap()
63 // TSAN-NOT: call void @__tsan_func_entry
64 // UBSAN-NOT: call void @__ubsan_handle
65 if (n)
66 x[n] = 42;
69 // CHECK-LABEL: define dso_local void @test_no_sanitize_separate(
70 __attribute__((no_sanitize("address")))
71 __attribute__((no_sanitize("memory")))
72 __attribute__((no_sanitize("thread")))
73 __attribute__((no_sanitize("bounds")))
74 __attribute__((no_sanitize("undefined")))
75 __attribute__((no_sanitize("coverage")))
76 void test_no_sanitize_separate(int n) {
77 // CHECK-NOT: call void @__sanitizer_cov_trace_pc
78 // CHECK-NOT: call void @__sanitizer_cov_trace_const_cmp
79 // ASAN-NOT: call void @__asan_report_store
80 // MSAN-NOT: call void @__msan_warning
81 // BOUNDS-NOT: call void @__ubsan_handle_out_of_bounds
82 // BOUNDS-NOT: call void @llvm.trap()
83 // TSAN-NOT: call void @__tsan_func_entry
84 // UBSAN-NOT: call void @__ubsan_handle
85 if (n)
86 x[n] = 42;
89 // CHECK-LABEL: define dso_local void @test_no_sanitize_kcfi(
90 __attribute__((no_sanitize("kcfi", "coverage")))
91 void test_no_sanitize_kcfi(void) {
92 // CHECK-NOT: call void @__sanitizer_cov_trace
93 // KCFI-NOT: call void %[[#]]() [ "kcfi"(i32 {{.*}}) ]
94 f();
97 // CHECK-LABEL: define dso_local void @test_no_sanitize_always_inline(
98 __attribute__((no_sanitize("coverage")))
99 void test_no_sanitize_always_inline(int n) {
100 // CHECK-NOT: call void @__sanitizer_cov_trace_pc
101 // CHECK-NOT: call void @__sanitizer_cov_trace_const_cmp
102 always_inlined_fn(n);
105 // CHECK-LABEL: declare void