llvm-project
77 строк · 2.8 Кб
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
4//
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
8//
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
12//
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
16//
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
20//
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
24//
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.
28
29#include <sanitizer/dfsan_interface.h>30
31#ifdef TEST6432typedef uint64_t FULL_TYPE;33typedef uint32_t HALF_TYPE;34#elif defined(TEST32)35typedef uint32_t FULL_TYPE;36typedef uint16_t HALF_TYPE;37#else38typedef uint16_t FULL_TYPE;39typedef uint8_t HALF_TYPE;40#endif41
42__attribute__((noinline)) FULL_TYPE foo(FULL_TYPE a, FULL_TYPE b) { return a + b; }43
44int main(int argc, char *argv[]) {45char x __attribute__((aligned(ALIGN))) = 1, y = 2;46dfsan_set_label(8, &x, sizeof(x));47char z __attribute__((aligned(ALIGN))) = x + y;48dfsan_print_origin_trace(&z, NULL);49
50FULL_TYPE a __attribute__((aligned(ALIGN))) = 1;51FULL_TYPE b = 10;52dfsan_set_label(4, (HALF_TYPE *)&a + 1, sizeof(HALF_TYPE));53FULL_TYPE c __attribute__((aligned(ALIGN))) = foo(a, b);54dfsan_print_origin_trace(&c, NULL);55dfsan_print_origin_trace((HALF_TYPE *)&c + 1, NULL);56}
57
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]]
61
62// CHECK: Origin value: {{.*}}, Taint value was created at
63// CHECK: #0 {{.*}} in main {{.*}}origin_ldst.c:[[@LINE-17]]
64
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]]
68
69// CHECK: Origin value: {{.*}}, Taint value was created at
70// CHECK: #0 {{.*}} in main {{.*}}origin_ldst.c:[[@LINE-18]]
71
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]]
75
76// CHECK: Origin value: {{.*}}, Taint value was created at
77// CHECK: #0 {{.*}} in main {{.*}}origin_ldst.c:[[@LINE-25]]
78