150
|
1 // Checks that dfsan works with trace-cmp instrumentation, even if some hooks
|
|
2 // are not defined (relies on week hooks implemented in dfsan).
|
|
3 //
|
|
4 // RUN: %clang_dfsan -fsanitize-coverage=trace-pc-guard,pc-table,func,trace-cmp %s -o %t
|
|
5 // RUN: %run %t 2>&1 | FileCheck %s
|
221
|
6 //
|
|
7 // REQUIRES: x86_64-target-arch
|
150
|
8
|
|
9 #include <stdio.h>
|
|
10 #include <stdint.h>
|
|
11 #include <stdlib.h>
|
|
12
|
|
13 #include <sanitizer/dfsan_interface.h>
|
|
14
|
|
15 uint32_t a4, b4;
|
|
16 uint64_t a8, b8;
|
|
17
|
|
18 // Define just two hooks, and leave others undefined.
|
|
19 void __dfsw___sanitizer_cov_trace_const_cmp4(uint8_t a, uint8_t b,
|
|
20 dfsan_label l1, dfsan_label l2) {
|
|
21 printf("const_cmp4 %d %d\n", a, b);
|
|
22 }
|
|
23 void __dfsw___sanitizer_cov_trace_cmp8(uint8_t a, uint8_t b, dfsan_label l1,
|
|
24 dfsan_label l2) {
|
|
25 printf("cmp8 %d %d\n", a, b);
|
|
26 }
|
|
27
|
|
28 int main(int argc, char **argv) {
|
|
29 printf("MAIN\n");
|
|
30 // CHECK: MAIN
|
|
31
|
|
32 if (a4 != b4) abort();
|
|
33 if (a4 == 42) abort();
|
|
34 // CHECK: const_cmp4 42 0
|
|
35 if (a8 != b8) abort();
|
|
36 // CHECK: cmp8 0 0
|
|
37 if (a8 == 66) abort();
|
|
38
|
|
39 switch (10 / (a4 + 2)) {
|
|
40 case 1: abort();
|
|
41 case 2: exit(1);
|
|
42 case 5:
|
|
43 printf("SWITCH OK\n");
|
|
44 break;
|
|
45 }
|
|
46 // CHECK: SWITCH OK
|
|
47
|
|
48
|
|
49 printf("DONE\n");
|
|
50 // CHECK: DONE
|
|
51 return 0;
|
|
52 }
|