1// RUN: %clang_dfsan -gmlt -mllvm -dfsan-track-origins=1 -mllvm -dfsan-fast-16-labels=true %s -o %t && \
2// RUN: %run %t >%t.out 2>&1
3// RUN: FileCheck %s --check-prefix=CHECK < %t.out
4//
5// RUN: %clang_dfsan -gmlt -mllvm -dfsan-track-origins=1 -mllvm -dfsan-fast-16-labels=true -mllvm -dfsan-instrument-with-call-threshold=0 %s -o %t && \
6// RUN: %run %t >%t.out 2>&1
7// RUN: FileCheck %s --check-prefix=CHECK < %t.out
8//
9// REQUIRES: x86_64-target-arch
10
11#include <sanitizer/dfsan_interface.h>
12
13#define NOINLINE __attribute__((noinline))
14
15NOINLINE int foo(int a, int b) { return a + b; }
16
17NOINLINE void bar(int depth, void *addr, int size) {
18 if (depth) {
19 bar(depth - 1, addr, size);
20 } else {
21 dfsan_set_label(1, addr, size);
22 }
23}
24
25NOINLINE void baz(int depth, void *addr, int size) {
26 bar(depth, addr, size);
27}
28
29int main(int argc, char *argv[]) {
30 int a = 10;
31 int b = 20;
32 baz(8, &a, sizeof(a));
33 int c = foo(a, b);
34 dfsan_print_origin_trace(&c, NULL);
35}
36
37// CHECK: Taint value 0x1 {{.*}} origin tracking ()
38// CHECK: Origin value: {{.*}}, Taint value was stored to memory at
39// CHECK: #0 {{.*}} in main {{.*}}origin_stack_trace.c:[[@LINE-6]]
40
41// CHECK: Origin value: {{.*}}, Taint value was created at
42// CHECK: #0 {{.*}} in dfs$bar {{.*}}origin_stack_trace.c:[[@LINE-21]]
43// CHECK-COUNT-8: #{{[0-9]+}} {{.*}} in dfs$bar {{.*}}origin_stack_trace.c:[[@LINE-24]]
44// CHECK: #9 {{.*}} in dfs$baz {{.*}}origin_stack_trace.c:[[@LINE-18]]
45