1 | // Tests dfsan_flush(). |
2 | // RUN: %clang_dfsan %s -o %t && %run %t |
3 | // RUN: %clang_dfsan -DORIGIN_TRACKING -mllvm -dfsan-track-origins=1 %s -o %t && %run %t |
4 | |
5 | #include <sanitizer/dfsan_interface.h> |
6 | #include <assert.h> |
7 | #include <stdlib.h> |
8 | |
9 | int global; |
10 | |
11 | int main() { |
12 | int local; |
13 | int *heap = (int*)malloc(size: sizeof(int)); |
14 | |
15 | dfsan_set_label(label: 10, addr: &global, size: sizeof(global)); |
16 | dfsan_set_label(label: 20, addr: &local, size: sizeof(local)); |
17 | dfsan_set_label(label: 30, addr: heap, size: sizeof(*heap)); |
18 | |
19 | assert(dfsan_get_label(global) == 10); |
20 | assert(dfsan_get_label(local) == 20); |
21 | assert(dfsan_get_label(*heap) == 30); |
22 | #ifdef ORIGIN_TRACKING |
23 | assert(dfsan_get_origin(global)); |
24 | assert(dfsan_get_origin(local)); |
25 | assert(dfsan_get_origin(*heap)); |
26 | #endif |
27 | |
28 | dfsan_flush(); |
29 | |
30 | assert(dfsan_get_label(global) == 0); |
31 | assert(dfsan_get_label(local) == 0); |
32 | assert(dfsan_get_label(*heap) == 0); |
33 | assert(dfsan_get_origin(global) == 0); |
34 | assert(dfsan_get_origin(local) == 0); |
35 | assert(dfsan_get_origin(*heap) == 0); |
36 | |
37 | free(ptr: heap); |
38 | } |
39 | |