annotate compiler-rt/test/dfsan/trace-cmp.c @ 222:81f6424ef0e3 llvm-original

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