llvm-project
38 строк · 987.0 Байт
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
9int global;
10
11int main() {
12int local;
13int *heap = (int*)malloc(sizeof(int));
14
15dfsan_set_label(10, &global, sizeof(global));
16dfsan_set_label(20, &local, sizeof(local));
17dfsan_set_label(30, heap, sizeof(*heap));
18
19assert(dfsan_get_label(global) == 10);
20assert(dfsan_get_label(local) == 20);
21assert(dfsan_get_label(*heap) == 30);
22#ifdef ORIGIN_TRACKING
23assert(dfsan_get_origin(global));
24assert(dfsan_get_origin(local));
25assert(dfsan_get_origin(*heap));
26#endif
27
28dfsan_flush();
29
30assert(dfsan_get_label(global) == 0);
31assert(dfsan_get_label(local) == 0);
32assert(dfsan_get_label(*heap) == 0);
33assert(dfsan_get_origin(global) == 0);
34assert(dfsan_get_origin(local) == 0);
35assert(dfsan_get_origin(*heap) == 0);
36
37free(heap);
38}
39