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