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
15char xx[10000];
16char yy[10000];
17volatile int idx = 30;
18
19__attribute__((noinline)) void fn_g(char a, char b) {
20 xx[idx] = a; xx[idx + 10] = b;
21}
22
23__attribute__((noinline)) void fn_f(char a, char b) {
24 fn_g(a, b);
25}
26
27__attribute__((noinline)) void fn_h() {
28 memcpy(&yy[2], &xx[2], sizeof(xx) - 4);
29}
30
31__attribute__((noinline)) void fn_i() {
32 memmove(&yy[25], &yy, 7500);
33}
34
35int main(int argc, char *argv[]) {
36 char volatile z1 = 0;
37 int volatile buffer = 0;
38 char volatile z2 = 0;
39 dfsan_set_label(8, (void *)&z1, sizeof(z1));
40 dfsan_set_label(16, (void *)&z2, sizeof(z2));
41 fn_f(z1, z2);
42 fn_h();
43 fn_i();
44 dfsan_print_origin_trace(&yy[25 + idx + OFFSET], NULL);
45 return 0;
46}
47
48// CHECK0: Taint value 0x8 {{.*}} origin tracking ()
49// CHECK0: Origin value: {{.*}}, Taint value was stored to memory at
50// CHECK0: #0 {{.*}} in dfs$fn_i {{.*}}origin_unaligned_memtrans.c:[[@LINE-18]]
51// CHECK0: #1 {{.*}} in main {{.*}}origin_unaligned_memtrans.c:[[@LINE-8]]
52
53// CHECK0: Origin value: {{.*}}, Taint value was stored to memory at
54// CHECK0: #0 {{.*}} in dfs$fn_h {{.*}}origin_unaligned_memtrans.c:[[@LINE-26]]
55// CHECK0: #1 {{.*}} in main {{.*}}origin_unaligned_memtrans.c:[[@LINE-13]]
56
57// CHECK0: Origin value: {{.*}}, Taint value was stored to memory at
58// CHECK0: #0 {{.*}} in dfs$fn_g {{.*}}origin_unaligned_memtrans.c:[[@LINE-38]]
59// CHECK0: #1 {{.*}} in dfs$fn_f {{.*}}origin_unaligned_memtrans.c:[[@LINE-35]]
60// CHECK0: #2 {{.*}} in main {{.*}}origin_unaligned_memtrans.c:[[@LINE-19]]
61
62// CHECK0: Origin value: {{.*}}, Taint value was created at
63// CHECK0: #0 {{.*}} in main {{.*}}origin_unaligned_memtrans.c:[[@LINE-24]]
64
65// CHECK10: Taint value 0x10 {{.*}} origin tracking
66// CHECK10: Origin value: {{.*}}, Taint value was stored to memory at
67// CHECK10: #0 {{.*}} in dfs$fn_i {{.*}}origin_unaligned_memtrans.c:[[@LINE-35]]
68// CHECK10: #1 {{.*}} in main {{.*}}origin_unaligned_memtrans.c:[[@LINE-25]]
69
70// CHECK10: Origin value: {{.*}}, Taint value was stored to memory at
71// CHECK10: #0 {{.*}} in dfs$fn_h {{.*}}origin_unaligned_memtrans.c:[[@LINE-43]]
72// CHECK10: #1 {{.*}} in main {{.*}}origin_unaligned_memtrans.c:[[@LINE-30]]
73
74// CHECK10: Origin value: {{.*}}, Taint value was stored to memory at
75// CHECK10: #0 {{.*}} in dfs$fn_g {{.*}}origin_unaligned_memtrans.c:[[@LINE-55]]
76// CHECK10: #1 {{.*}} in dfs$fn_f {{.*}}origin_unaligned_memtrans.c:[[@LINE-52]]
77// CHECK10: #2 {{.*}} in main {{.*}}origin_unaligned_memtrans.c:[[@LINE-36]]
78
79// CHECK10: Origin value: {{.*}}, Taint value was created at
80// CHECK10: #0 {{.*}} in main {{.*}}origin_unaligned_memtrans.c:[[@LINE-40]]
81