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