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];
16
17volatile int idx = 30;
18
19__attribute__((noinline))
20void fn_g(int a, int b) {
21 memset(&xx[idx], a, sizeof(a));
22 memset(&xx[idx + 10], b, sizeof(b));
23}
24
25__attribute__((noinline))
26void fn_f(int a, int b) {
27 fn_g(a, b);
28}
29
30int main(int argc, char *argv[]) {
31 int volatile z1;
32 int volatile z2;
33 dfsan_set_label(8, (void *)&z1, sizeof(z1));
34 dfsan_set_label(16, (void *)&z2, sizeof(z2));
35 fn_f(z1, z2);
36 dfsan_print_origin_trace(&xx[idx + OFFSET], NULL);
37 return 0;
38}
39
40// CHECK0: Taint value 0x8 {{.*}} origin tracking ()
41// CHECK0: Origin value: {{.*}}, Taint value was created at
42
43// CHECK0: #0 {{.*}} in main {{.*}}origin_memset.c:[[@LINE-10]]
44
45// CHECK10: Taint value 0x10 {{.*}} origin tracking ()
46// CHECK10: Origin value: {{.*}}, Taint value was created at
47
48// CHECK10: #0 {{.*}} in main {{.*}}origin_memset.c:[[@LINE-14]]
49