[docs] Fix build-docs.sh
[llvm-project.git] / compiler-rt / test / dfsan / flush.c
blob6c74ce5eb35ef87e5769a0b9e697450009ca6442
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 // REQUIRES: x86_64-target-arch
7 #include <sanitizer/dfsan_interface.h>
8 #include <assert.h>
9 #include <stdlib.h>
11 int global;
13 int main() {
14 int local;
15 int *heap = (int*)malloc(sizeof(int));
17 dfsan_set_label(10, &global, sizeof(global));
18 dfsan_set_label(20, &local, sizeof(local));
19 dfsan_set_label(30, heap, sizeof(*heap));
21 assert(dfsan_get_label(global) == 10);
22 assert(dfsan_get_label(local) == 20);
23 assert(dfsan_get_label(*heap) == 30);
24 #ifdef ORIGIN_TRACKING
25 assert(dfsan_get_origin(global));
26 assert(dfsan_get_origin(local));
27 assert(dfsan_get_origin(*heap));
28 #endif
30 dfsan_flush();
32 assert(dfsan_get_label(global) == 0);
33 assert(dfsan_get_label(local) == 0);
34 assert(dfsan_get_label(*heap) == 0);
35 assert(dfsan_get_origin(global) == 0);
36 assert(dfsan_get_origin(local) == 0);
37 assert(dfsan_get_origin(*heap) == 0);
39 free(heap);