1 // RUN: %clang_dfsan -gmlt -DTEST64 -DALIGN=8 -mllvm -dfsan-track-origins=1 %s -o %t && \
2 // RUN: %run %t >%t.out 2>&1
3 // RUN: FileCheck %s < %t.out
5 // RUN: %clang_dfsan -gmlt -DTEST32 -DALIGN=4 -mllvm -dfsan-track-origins=1 %s -o %t && \
6 // RUN: %run %t >%t.out 2>&1
7 // RUN: FileCheck %s < %t.out
9 // RUN: %clang_dfsan -gmlt -DALIGN=2 -mllvm -dfsan-track-origins=1 %s -o %t && \
10 // RUN: %run %t >%t.out 2>&1
11 // RUN: FileCheck %s < %t.out
13 // RUN: %clang_dfsan -gmlt -DTEST64 -DALIGN=4 -mllvm -dfsan-track-origins=1 %s -o %t && \
14 // RUN: %run %t >%t.out 2>&1
15 // RUN: FileCheck %s < %t.out
17 // RUN: %clang_dfsan -gmlt -DTEST32 -DALIGN=2 -mllvm -dfsan-track-origins=1 %s -o %t && \
18 // RUN: %run %t >%t.out 2>&1
19 // RUN: FileCheck %s < %t.out
21 // RUN: %clang_dfsan -gmlt -DALIGN=1 -mllvm -dfsan-track-origins=1 %s -o %t && \
22 // RUN: %run %t >%t.out 2>&1
23 // RUN: FileCheck %s < %t.out
25 // Test origin tracking is accurate in terms of partial store/load, and
26 // different aligments. Do not test alignments that are not power of 2.
27 // Compilers do not always allow this.
29 #include <sanitizer/dfsan_interface.h>
32 typedef uint64_t FULL_TYPE
;
33 typedef uint32_t HALF_TYPE
;
35 typedef uint32_t FULL_TYPE
;
36 typedef uint16_t HALF_TYPE
;
38 typedef uint16_t FULL_TYPE
;
39 typedef uint8_t HALF_TYPE
;
42 __attribute__((noinline
)) FULL_TYPE
foo(FULL_TYPE a
, FULL_TYPE b
) { return a
+ b
; }
44 int main(int argc
, char *argv
[]) {
45 char x
__attribute__((aligned(ALIGN
))) = 1, y
= 2;
46 dfsan_set_label(8, &x
, sizeof(x
));
47 char z
__attribute__((aligned(ALIGN
))) = x
+ y
;
48 dfsan_print_origin_trace(&z
, NULL
);
50 FULL_TYPE a
__attribute__((aligned(ALIGN
))) = 1;
52 dfsan_set_label(4, (HALF_TYPE
*)&a
+ 1, sizeof(HALF_TYPE
));
53 FULL_TYPE c
__attribute__((aligned(ALIGN
))) = foo(a
, b
);
54 dfsan_print_origin_trace(&c
, NULL
);
55 dfsan_print_origin_trace((HALF_TYPE
*)&c
+ 1, NULL
);
58 // CHECK: Taint value 0x8 {{.*}} origin tracking ()
59 // CHECK: Origin value: {{.*}}, Taint value was stored to memory at
60 // CHECK: #0 {{.*}} in main {{.*}}origin_ldst.c:[[@LINE-13]]
62 // CHECK: Origin value: {{.*}}, Taint value was created at
63 // CHECK: #0 {{.*}} in main {{.*}}origin_ldst.c:[[@LINE-17]]
65 // CHECK: Taint value 0x4 {{.*}} origin tracking ()
66 // CHECK: Origin value: {{.*}}, Taint value was stored to memory at
67 // CHECK: #0 {{.*}} in main {{.*}}origin_ldst.c:[[@LINE-14]]
69 // CHECK: Origin value: {{.*}}, Taint value was created at
70 // CHECK: #0 {{.*}} in main {{.*}}origin_ldst.c:[[@LINE-18]]
72 // CHECK: Taint value 0x4 {{.*}} origin tracking ()
73 // CHECK: Origin value: {{.*}}, Taint value was stored to memory at
74 // CHECK: #0 {{.*}} in main {{.*}}origin_ldst.c:[[@LINE-21]]
76 // CHECK: Origin value: {{.*}}, Taint value was created at
77 // CHECK: #0 {{.*}} in main {{.*}}origin_ldst.c:[[@LINE-25]]