1// RUN: %clang_dfsan -gmlt -DOFFSET=0 -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=CHECK0 < %t.out
4//
5// RUN: %clang_dfsan -gmlt -DOFFSET=10 -mllvm -dfsan-track-origins=1 -mllvm -dfsan-fast-16-labels=true %s -o %t && \
6// RUN: %run %t >%t.out 2>&1
7// RUN: FileCheck %s --check-prefix=CHECK10 < %t.out
8//
9// REQUIRES: x86_64-target-arch
10
11#include <sanitizer/dfsan_interface.h>
12
13#include <string.h>
14
15int xx[10000];
16int yy[10000];
17volatile int idx = 30;
18
19__attribute__((noinline))
20void fn_g(int a, int b) {
21 xx[idx] = a; xx[idx + 10] = b;
22}
23
24__attribute__((noinline))
25void fn_f(int a, int b) {
26 fn_g(a, b);
27}
28
29__attribute__((noinline))
30void fn_h() {
31 memcpy(&yy, &xx, sizeof(xx));
32}
33
34int main(int argc, char *argv[]) {
35 int volatile z1 = 0;
36 int volatile z2 = 0;
37 dfsan_set_label(8, (void *)&z1, sizeof(z1));
38 dfsan_set_label(16, (void *)&z2, sizeof(z2));
39 fn_f(z1, z2);
40 fn_h();
41 dfsan_print_origin_trace(&yy[idx + OFFSET], NULL);
42 return 0;
43}
44
45// CHECK0: Taint value 0x8 {{.*}} origin tracking ()
46// CHECK0: Origin value: {{.*}}, Taint value was stored to memory at
47// CHECK0: #0 {{.*}} in dfs$fn_h {{.*}}origin_memcpy.c:[[@LINE-16]]
48// CHECK0: #1 {{.*}} in main {{.*}}origin_memcpy.c:[[@LINE-8]]
49
50// CHECK0: Origin value: {{.*}}, Taint value was stored to memory at
51// CHECK0: #0 {{.*}} in dfs$fn_g {{.*}}origin_memcpy.c:[[@LINE-30]]
52// CHECK0: #1 {{.*}} in dfs$fn_f {{.*}}origin_memcpy.c:[[@LINE-26]]
53// CHECK0: #2 {{.*}} in main {{.*}}origin_memcpy.c:[[@LINE-14]]
54
55// CHECK0: Origin value: {{.*}}, Taint value was created at
56// CHECK0: #0 {{.*}} in main {{.*}}origin_memcpy.c:[[@LINE-19]]
57
58// CHECK10: Taint value 0x10 {{.*}} origin tracking ()
59// CHECK10: Origin value: {{.*}}, Taint value was stored to memory at
60// CHECK10: #0 {{.*}} in dfs$fn_h {{.*}}origin_memcpy.c:[[@LINE-29]]
61// CHECK10: #1 {{.*}} in main {{.*}}origin_memcpy.c:[[@LINE-21]]
62
63// CHECK10: Origin value: {{.*}}, Taint value was stored to memory at
64// CHECK10: #0 {{.*}} in dfs$fn_g {{.*}}origin_memcpy.c:[[@LINE-43]]
65// CHECK10: #1 {{.*}} in dfs$fn_f {{.*}}origin_memcpy.c:[[@LINE-39]]
66// CHECK10: #2 {{.*}} in main {{.*}}origin_memcpy.c:[[@LINE-27]]
67
68// CHECK10: Origin value: {{.*}}, Taint value was created at
69// CHECK10: #0 {{.*}} in main {{.*}}origin_memcpy.c:[[@LINE-31]]
70