1// RUN: %clang_dfsan -gmlt -mllvm -dfsan-track-origins=1 %s -o %t
2//
3// RUN: %run %t >%t.out 2>&1
4// RUN: FileCheck %s < %t.out
5//
6// RUN: DFSAN_OPTIONS=origin_history_size=2 %run %t >%t.out 2>&1
7// RUN: FileCheck %s --check-prefix=CHECK2 < %t.out
8//
9// RUN: DFSAN_OPTIONS=origin_history_size=0 %run %t >%t.out 2>&1
10// RUN: FileCheck %s --check-prefix=CHECK0 < %t.out
11
12#include <sanitizer/dfsan_interface.h>
13
14#include <stdio.h>
15
16__attribute__((noinline)) int foo(int a, int b) { return a + b; }
17
18int main(int argc, char *argv[]) {
19 int a = 10;
20 dfsan_set_label(label: 8, addr: &a, size: sizeof(a));
21 int c = 0;
22 for (int i = 0; i < 17; ++i) {
23 c = foo(a, b: c);
24 printf(format: "%lx", (unsigned long)&c);
25 }
26 dfsan_print_origin_trace(addr: &c, NULL);
27}
28
29// CHECK: Taint value 0x8 {{.*}} origin tracking ()
30// CHECK-COUNT 14: Origin value: {{.*}}, Taint value was stored to memory at
31// CHECK: Origin value: {{.*}}, Taint value was created at
32
33// CHECK2: Taint value 0x8 {{.*}} origin tracking ()
34// CHECK2: Origin value: {{.*}}, Taint value was stored to memory at
35// CHECK2: Origin value: {{.*}}, Taint value was created at
36
37// CHECK0: Taint value 0x8 {{.*}} origin tracking ()
38// CHECK0-COUNT 16: Origin value: {{.*}}, Taint value was stored to memory at
39// CHECK0: Origin value: {{.*}}, Taint value was created at
40

source code of compiler-rt/test/dfsan/origin_limit.c