Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / dfsan / reaches_function.c
blob9e2bcee935b2ac923fa5b775291a85f7683fc2cc
1 // RUN: %clang_dfsan -fno-sanitize=dataflow -O2 -fPIE -DCALLBACKS -c %s -o %t-callbacks.o
2 // RUN: %clang_dfsan -gmlt -fsanitize-ignorelist=%S/Inputs/flags_abilist.txt -O2 -mllvm -dfsan-reaches-function-callbacks=1 %s %t-callbacks.o -o %t
3 // RUN: %run %t 2>&1 | FileCheck %s
5 // RUN: %clang_dfsan -fno-sanitize=dataflow -O2 -fPIE -DCALLBACKS -DORIGIN_TRACKING -c %s -o %t-callbacks.o
6 // RUN: %clang_dfsan -gmlt -fsanitize-ignorelist=%S/Inputs/flags_abilist.txt -O2 -mllvm -dfsan-reaches-function-callbacks=1 -mllvm -dfsan-track-origins=2 %s %t-callbacks.o -o %t
7 // RUN: %run %t 2>&1 | FileCheck --check-prefix=CHECK-ORIGIN-TRACKING %s
9 // Tests that callbacks are inserted for reached functions when
10 // -dfsan-reaches-function-callbacks is specified.
12 #include <assert.h>
13 #include <stdio.h>
14 #include <string.h>
15 #include <sanitizer/dfsan_interface.h>
17 #ifdef CALLBACKS
18 // Compile this code without DFSan to avoid recursive instrumentation.
20 void my_dfsan_reaches_function_callback(dfsan_label label, dfsan_origin origin,
21 const char *file, unsigned int line,
22 const char *function) {
23 #ifdef ORIGIN_TRACKING
24 dfsan_print_origin_id_trace(origin);
25 #else
26 printf("%s:%d %s\n", file, line, function);
27 #endif
30 #else
32 __attribute__((noinline)) uint64_t add(uint64_t *a, uint64_t *b) {
34 return *a + *b;
35 // CHECK: {{.*}}compiler-rt/test/dfsan/reaches_function.c:[[# @LINE - 1]] add.dfsan
36 // CHECK-ORIGIN-TRACKING: Origin value: 0x10000002, Taint value was stored to memory at
37 // CHECK-ORIGIN-TRACKING: #0 {{.*}} in add.dfsan {{.*}}compiler-rt/test/dfsan/reaches_function.c:[[# @LINE - 3]]:{{.*}}
38 // CHECK-ORIGIN-TRACKING: Origin value: 0x1, Taint value was created at
39 // CHECK-ORIGIN-TRACKING: #0 {{.*}} in main {{.*}}compiler-rt/test/dfsan/reaches_function.c:{{.*}}
42 extern void my_dfsan_reaches_function_callback(dfsan_label label,
43 dfsan_origin origin,
44 const char *file,
45 unsigned int line,
46 const char *function);
48 int main(int argc, char *argv[]) {
50 dfsan_set_reaches_function_callback(my_dfsan_reaches_function_callback);
52 uint64_t a = 0;
53 uint64_t b = 0;
55 dfsan_set_label(8, &a, sizeof(a));
56 uint64_t c = add(&a, &b);
57 // CHECK: {{.*}}compiler-rt/test/dfsan/reaches_function.c:[[# @LINE - 1]] main
58 // CHECK-ORIGIN-TRACKING: Origin value: 0x10000002, Taint value was stored to memory at
59 // CHECK-ORIGIN-TRACKING: #0 {{.*}} in add.dfsan {{.*}}compiler-rt/test/dfsan/reaches_function.c:{{.*}}
60 // CHECK-ORIGIN-TRACKING: Origin value: 0x1, Taint value was created at
61 // CHECK-ORIGIN-TRACKING: #0 {{.*}} in main {{.*}}compiler-rt/test/dfsan/reaches_function.c:[[# @LINE - 6]]:{{.*}}
62 return c;
65 #endif // #ifdef CALLBACKS