78 lines · c
1// RUN: %clang_dfsan -gmlt -DTEST64 -DALIGN=8 -mllvm -dfsan-track-origins=1 %s -o %t && \2// RUN: %run %t >%t.out 2>&13// RUN: FileCheck %s < %t.out4//5// RUN: %clang_dfsan -gmlt -DTEST32 -DALIGN=4 -mllvm -dfsan-track-origins=1 %s -o %t && \6// RUN: %run %t >%t.out 2>&17// RUN: FileCheck %s < %t.out8//9// RUN: %clang_dfsan -gmlt -DALIGN=2 -mllvm -dfsan-track-origins=1 %s -o %t && \10// RUN: %run %t >%t.out 2>&111// RUN: FileCheck %s < %t.out12//13// RUN: %clang_dfsan -gmlt -DTEST64 -DALIGN=4 -mllvm -dfsan-track-origins=1 %s -o %t && \14// RUN: %run %t >%t.out 2>&115// RUN: FileCheck %s < %t.out16//17// RUN: %clang_dfsan -gmlt -DTEST32 -DALIGN=2 -mllvm -dfsan-track-origins=1 %s -o %t && \18// RUN: %run %t >%t.out 2>&119// RUN: FileCheck %s < %t.out20//21// RUN: %clang_dfsan -gmlt -DALIGN=1 -mllvm -dfsan-track-origins=1 %s -o %t && \22// RUN: %run %t >%t.out 2>&123// RUN: FileCheck %s < %t.out24//25// Test origin tracking is accurate in terms of partial store/load, and26// 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[]) {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);49 50 FULL_TYPE a __attribute__((aligned(ALIGN))) = 1;51 FULL_TYPE b = 10;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);56}57 58// CHECK: Taint value 0x8 {{.*}} origin tracking ()59// CHECK: Origin value: {{.*}}, Taint value was stored to memory at60// CHECK: #0 {{.*}} in main {{.*}}origin_ldst.c:[[@LINE-13]]61 62// CHECK: Origin value: {{.*}}, Taint value was created at63// 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 at67// CHECK: #0 {{.*}} in main {{.*}}origin_ldst.c:[[@LINE-14]]68 69// CHECK: Origin value: {{.*}}, Taint value was created at70// 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 at74// CHECK: #0 {{.*}} in main {{.*}}origin_ldst.c:[[@LINE-21]]75 76// CHECK: Origin value: {{.*}}, Taint value was created at77// CHECK: #0 {{.*}} in main {{.*}}origin_ldst.c:[[@LINE-25]]78