1// Tests -fsanitize-coverage-allowlist=allowlist.txt and
2// -fsanitize-coverage-ignorelist=ignorelist.txt with libFuzzer-like coverage
3// options
4
5// REQUIRES: has_sancovcc,stable-runtime
6// UNSUPPORTED: darwin
7// XFAIL: ubsan,tsan
8// XFAIL: android && asan
9
10// RUN: DIR=%t_workdir
11// RUN: rm -rf $DIR
12// RUN: mkdir -p $DIR
13// RUN: cd $DIR
14
15// RUN: echo -e "src:*\nfun:*" > al_all.txt
16// RUN: echo -e "" > al_none.txt
17// RUN: echo -e "src:%s\nfun:*" > al_file.txt
18// RUN: echo -e "src:*\nfun:*bar*" > al_bar.txt
19// RUN: echo -e "src:*\nfun:*foo*" > al_foo.txt
20// RUN: echo -e "src:*" > bl_all.txt
21// RUN: echo -e "" > bl_none.txt
22// RUN: echo -e "src:%s" > bl_file.txt
23// RUN: echo -e "fun:*foo*" > bl_foo.txt
24// RUN: echo -e "fun:*bar*" > bl_bar.txt
25
26// Check inline-8bit-counters
27// RUN: echo 'section "__sancov_cntrs"' > patterns.txt
28// RUN: echo '%[0-9]\+ = load i8, ptr @__sancov_gen_' >> patterns.txt
29// RUN: echo 'store i8 %[0-9]\+, ptr @__sancov_gen_' >> patterns.txt
30// RUN: echo '%[0-9]\+ = load i8, ptr getelementptr inbounds (\[[0-9]\+ x i8\], ptr @__sancov_gen_' >> patterns.txt
31// RUN: echo 'store i8 %[0-9]\+, ptr getelementptr inbounds (\[[0-9]\+ x i8\], ptr @__sancov_gen_' >> patterns.txt
32
33// Check indirect-calls
34// RUN: echo 'call void @__sanitizer_cov_trace_pc_indir' >> patterns.txt
35
36// Check trace-cmp
37// RUN: echo 'call void @__sanitizer_cov_trace_cmp4' >> patterns.txt
38
39// Check pc-table
40// RUN: echo 'section "__sancov_pcs"' >> patterns.txt
41
42// RUN: %clangxx -O0 %s -S -o - -emit-llvm -fsanitize-coverage=inline-8bit-counters,indirect-calls,trace-cmp,pc-table 2>&1 | grep -f patterns.txt | count 14
43// RUN: %clangxx -O0 %s -S -o - -emit-llvm -fsanitize-coverage=inline-8bit-counters,indirect-calls,trace-cmp,pc-table -fsanitize-coverage-allowlist=al_all.txt 2>&1 | grep -f patterns.txt | count 14
44// RUN: %clangxx -O0 %s -S -o - -emit-llvm -fsanitize-coverage=inline-8bit-counters,indirect-calls,trace-cmp,pc-table -fsanitize-coverage-allowlist=al_none.txt 2>&1 | not grep -f patterns.txt
45// RUN: %clangxx -O0 %s -S -o - -emit-llvm -fsanitize-coverage=inline-8bit-counters,indirect-calls,trace-cmp,pc-table -fsanitize-coverage-allowlist=al_file.txt 2>&1 | grep -f patterns.txt | count 14
46// RUN: %clangxx -O0 %s -S -o - -emit-llvm -fsanitize-coverage=inline-8bit-counters,indirect-calls,trace-cmp,pc-table -fsanitize-coverage-allowlist=al_foo.txt 2>&1 | grep -f patterns.txt | count 9
47// RUN: %clangxx -O0 %s -S -o - -emit-llvm -fsanitize-coverage=inline-8bit-counters,indirect-calls,trace-cmp,pc-table -fsanitize-coverage-allowlist=al_bar.txt 2>&1 | grep -f patterns.txt | count 5
48
49// RUN: %clangxx -O0 %s -S -o - -emit-llvm -fsanitize-coverage=inline-8bit-counters,indirect-calls,trace-cmp,pc-table -fsanitize-coverage-ignorelist=bl_all.txt 2>&1 | not grep -f patterns.txt
50// RUN: %clangxx -O0 %s -S -o - -emit-llvm -fsanitize-coverage=inline-8bit-counters,indirect-calls,trace-cmp,pc-table -fsanitize-coverage-allowlist=al_all.txt -fsanitize-coverage-ignorelist=bl_all.txt 2>&1 | not grep -f patterns.txt
51// RUN: %clangxx -O0 %s -S -o - -emit-llvm -fsanitize-coverage=inline-8bit-counters,indirect-calls,trace-cmp,pc-table -fsanitize-coverage-allowlist=al_none.txt -fsanitize-coverage-ignorelist=bl_all.txt 2>&1 | not grep -f patterns.txt
52// RUN: %clangxx -O0 %s -S -o - -emit-llvm -fsanitize-coverage=inline-8bit-counters,indirect-calls,trace-cmp,pc-table -fsanitize-coverage-allowlist=al_file.txt -fsanitize-coverage-ignorelist=bl_all.txt 2>&1 | not grep -f patterns.txt
53// RUN: %clangxx -O0 %s -S -o - -emit-llvm -fsanitize-coverage=inline-8bit-counters,indirect-calls,trace-cmp,pc-table -fsanitize-coverage-allowlist=al_foo.txt -fsanitize-coverage-ignorelist=bl_all.txt 2>&1 | not grep -f patterns.txt
54// RUN: %clangxx -O0 %s -S -o - -emit-llvm -fsanitize-coverage=inline-8bit-counters,indirect-calls,trace-cmp,pc-table -fsanitize-coverage-allowlist=al_bar.txt -fsanitize-coverage-ignorelist=bl_all.txt 2>&1 | not grep -f patterns.txt
55
56// RUN: %clangxx -O0 %s -S -o - -emit-llvm -fsanitize-coverage=inline-8bit-counters,indirect-calls,trace-cmp,pc-table -fsanitize-coverage-ignorelist=bl_none.txt 2>&1 | grep -f patterns.txt | count 14
57// RUN: %clangxx -O0 %s -S -o - -emit-llvm -fsanitize-coverage=inline-8bit-counters,indirect-calls,trace-cmp,pc-table -fsanitize-coverage-allowlist=al_all.txt -fsanitize-coverage-ignorelist=bl_none.txt 2>&1 | grep -f patterns.txt | count 14
58// RUN: %clangxx -O0 %s -S -o - -emit-llvm -fsanitize-coverage=inline-8bit-counters,indirect-calls,trace-cmp,pc-table -fsanitize-coverage-allowlist=al_none.txt -fsanitize-coverage-ignorelist=bl_none.txt 2>&1 | not grep -f patterns.txt
59// RUN: %clangxx -O0 %s -S -o - -emit-llvm -fsanitize-coverage=inline-8bit-counters,indirect-calls,trace-cmp,pc-table -fsanitize-coverage-allowlist=al_file.txt -fsanitize-coverage-ignorelist=bl_none.txt 2>&1 | grep -f patterns.txt | count 14
60// RUN: %clangxx -O0 %s -S -o - -emit-llvm -fsanitize-coverage=inline-8bit-counters,indirect-calls,trace-cmp,pc-table -fsanitize-coverage-allowlist=al_foo.txt -fsanitize-coverage-ignorelist=bl_none.txt 2>&1 | grep -f patterns.txt | count 9
61// RUN: %clangxx -O0 %s -S -o - -emit-llvm -fsanitize-coverage=inline-8bit-counters,indirect-calls,trace-cmp,pc-table -fsanitize-coverage-allowlist=al_bar.txt -fsanitize-coverage-ignorelist=bl_none.txt 2>&1 | grep -f patterns.txt | count 5
62
63// RUN: %clangxx -O0 %s -S -o - -emit-llvm -fsanitize-coverage=inline-8bit-counters,indirect-calls,trace-cmp,pc-table -fsanitize-coverage-ignorelist=bl_file.txt 2>&1 | not grep -f patterns.txt
64// RUN: %clangxx -O0 %s -S -o - -emit-llvm -fsanitize-coverage=inline-8bit-counters,indirect-calls,trace-cmp,pc-table -fsanitize-coverage-allowlist=al_all.txt -fsanitize-coverage-ignorelist=bl_file.txt 2>&1 | not grep -f patterns.txt
65// RUN: %clangxx -O0 %s -S -o - -emit-llvm -fsanitize-coverage=inline-8bit-counters,indirect-calls,trace-cmp,pc-table -fsanitize-coverage-allowlist=al_none.txt -fsanitize-coverage-ignorelist=bl_file.txt 2>&1 | not grep -f patterns.txt
66// RUN: %clangxx -O0 %s -S -o - -emit-llvm -fsanitize-coverage=inline-8bit-counters,indirect-calls,trace-cmp,pc-table -fsanitize-coverage-allowlist=al_file.txt -fsanitize-coverage-ignorelist=bl_file.txt 2>&1 | not grep -f patterns.txt
67// RUN: %clangxx -O0 %s -S -o - -emit-llvm -fsanitize-coverage=inline-8bit-counters,indirect-calls,trace-cmp,pc-table -fsanitize-coverage-allowlist=al_foo.txt -fsanitize-coverage-ignorelist=bl_file.txt 2>&1 | not grep -f patterns.txt
68// RUN: %clangxx -O0 %s -S -o - -emit-llvm -fsanitize-coverage=inline-8bit-counters,indirect-calls,trace-cmp,pc-table -fsanitize-coverage-allowlist=al_bar.txt -fsanitize-coverage-ignorelist=bl_file.txt 2>&1 | not grep -f patterns.txt
69
70// RUN: %clangxx -O0 %s -S -o - -emit-llvm -fsanitize-coverage=inline-8bit-counters,indirect-calls,trace-cmp,pc-table -fsanitize-coverage-ignorelist=bl_foo.txt 2>&1 | grep -f patterns.txt | count 5
71// RUN: %clangxx -O0 %s -S -o - -emit-llvm -fsanitize-coverage=inline-8bit-counters,indirect-calls,trace-cmp,pc-table -fsanitize-coverage-allowlist=al_all.txt -fsanitize-coverage-ignorelist=bl_foo.txt 2>&1 | grep -f patterns.txt | count 5
72// RUN: %clangxx -O0 %s -S -o - -emit-llvm -fsanitize-coverage=inline-8bit-counters,indirect-calls,trace-cmp,pc-table -fsanitize-coverage-allowlist=al_none.txt -fsanitize-coverage-ignorelist=bl_foo.txt 2>&1 | not grep -f patterns.txt
73// RUN: %clangxx -O0 %s -S -o - -emit-llvm -fsanitize-coverage=inline-8bit-counters,indirect-calls,trace-cmp,pc-table -fsanitize-coverage-allowlist=al_file.txt -fsanitize-coverage-ignorelist=bl_foo.txt 2>&1 | grep -f patterns.txt | count 5
74// RUN: %clangxx -O0 %s -S -o - -emit-llvm -fsanitize-coverage=inline-8bit-counters,indirect-calls,trace-cmp,pc-table -fsanitize-coverage-allowlist=al_foo.txt -fsanitize-coverage-ignorelist=bl_foo.txt 2>&1 | not grep -f patterns.txt
75// RUN: %clangxx -O0 %s -S -o - -emit-llvm -fsanitize-coverage=inline-8bit-counters,indirect-calls,trace-cmp,pc-table -fsanitize-coverage-allowlist=al_bar.txt -fsanitize-coverage-ignorelist=bl_foo.txt 2>&1 | grep -f patterns.txt | count 5
76
77// RUN: %clangxx -O0 %s -S -o - -emit-llvm -fsanitize-coverage=inline-8bit-counters,indirect-calls,trace-cmp,pc-table -fsanitize-coverage-ignorelist=bl_bar.txt 2>&1 | grep -f patterns.txt | count 9
78// RUN: %clangxx -O0 %s -S -o - -emit-llvm -fsanitize-coverage=inline-8bit-counters,indirect-calls,trace-cmp,pc-table -fsanitize-coverage-allowlist=al_all.txt -fsanitize-coverage-ignorelist=bl_bar.txt 2>&1 | grep -f patterns.txt | count 9
79// RUN: %clangxx -O0 %s -S -o - -emit-llvm -fsanitize-coverage=inline-8bit-counters,indirect-calls,trace-cmp,pc-table -fsanitize-coverage-allowlist=al_none.txt -fsanitize-coverage-ignorelist=bl_bar.txt 2>&1 | not grep -f patterns.txt
80// RUN: %clangxx -O0 %s -S -o - -emit-llvm -fsanitize-coverage=inline-8bit-counters,indirect-calls,trace-cmp,pc-table -fsanitize-coverage-allowlist=al_file.txt -fsanitize-coverage-ignorelist=bl_bar.txt 2>&1 | grep -f patterns.txt | count 9
81// RUN: %clangxx -O0 %s -S -o - -emit-llvm -fsanitize-coverage=inline-8bit-counters,indirect-calls,trace-cmp,pc-table -fsanitize-coverage-allowlist=al_foo.txt -fsanitize-coverage-ignorelist=bl_bar.txt 2>&1 | grep -f patterns.txt | count 9
82// RUN: %clangxx -O0 %s -S -o - -emit-llvm -fsanitize-coverage=inline-8bit-counters,indirect-calls,trace-cmp,pc-table -fsanitize-coverage-allowlist=al_bar.txt -fsanitize-coverage-ignorelist=bl_bar.txt 2>&1 | not grep -f patterns.txt
83
84// RUN: cd -
85// RUN: rm -rf $DIR
86
87// foo has 3 instrumentation points, 0 indirect call, 1 comparison point
88
89// Expected results with patterns.txt when foo gets instrumentation with
90// libFuzzer-like coverage options: 9 lines
91// inline-8bit-counters ->
92// @__sancov_gen_XX = private global [3 x i8] zeroinitializer, section "__sancov_cntrs"...
93// %XX = load i8, ptr @__sancov_gen_...
94// %XX = load i8, ptr getelementptr inbounds ([3 x i8], ptr @__sancov_gen_, i64 0, i64 1)...
95// %XX = load i8, ptr getelementptr inbounds ([3 x i8], ptr @__sancov_gen_, i64 0, i64 2)...
96// store i8 %XX, ptr @__sancov_gen_...
97// store i8 %XX, ptr getelementptr inbounds ([3 x i8], ptr @__sancov_gen_, i64 0, i64 1)...
98// store i8 %XX, ptr getelementptr inbounds ([3 x i8], ptr @__sancov_gen_, i64 0, i64 2)...
99// trace-cmp ->
100// call void @__sanitizer_cov_trace_cmp4(i32 %XX, i32 %XX)
101// pc-table ->
102// @__sancov_gen_XX = private constant [6 x ptr] ..., section "__sancov_pcs"...
103
104bool foo(int *a, int *b) {
105 if (*a == *b) {
106 return true;
107 }
108 return false;
109}
110
111// bar has 1 instrumentation point, 1 indirect call, 0 comparison point
112
113// Expected results with patterns.txt when bar gets instrumentation with
114// libFuzzer-like coverage options: 5 lines
115// inline-8bit-counters ->
116// @__sancov_gen_XX = private global [1 x i8] zeroinitializer, section "__sancov_cntrs"...
117// %XX = load i8, ptr @__sancov_gen_.2, ...
118// store i8 %XX, ptr @__sancov_gen_.2, ...
119// indirect-calls ->
120// call void @__sanitizer_cov_trace_pc_indir(i64 %XX)
121// pc-table ->
122// @__sancov_gen_XX = private constant [2 x ptr] ..., section "__sancov_pcs"...
123
124void bar(void (*f)()) { f(); }
125

source code of compiler-rt/test/sanitizer_common/TestCases/sanitizer_coverage_allowlist_ignorelist.cpp