1 // RUN: %clang_dfsan -gmlt -mllvm -dfsan-track-origins=1 %s -o %t && \
2 // RUN: %run %t >%t.out 2>&1
3 // RUN: FileCheck %s < %t.out
4 //
5 // REQUIRES: x86_64-target-arch
6
7 #include <sanitizer/dfsan_interface.h>
8
main(int argc,char * argv[])9 int main(int argc, char *argv[]) {
10 uint64_t a = 10;
11 dfsan_set_label(1, &a, sizeof(a));
12
13 // Manually compute origin address for &a.
14 // See x86 MEM_TO_ORIGIN macro for logic to replicate here.
15 // Alignment is also needed after to MEM_TO_ORIGIN.
16 uint64_t origin_addr =
17 (((uint64_t)&a ^ 0x500000000000ULL) + 0x100000000000ULL) & ~0x3ULL;
18
19 // Take the address we computed, and store 0 in it to mess it up.
20 asm("mov %0, %%rax": :"r"(origin_addr));
21 asm("movq $0, (%rax)");
22 dfsan_print_origin_trace(&a, "invalid");
23 }
24
25 // CHECK: Taint value 0x1 (at {{.*}}) origin tracking (invalid)
26 // CHECK: Taint value 0x1 (at {{.*}}) has invalid origin tracking. This can be a DFSan bug.
27