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

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