1 // RUN: %clang_dfsan %s -o %t && %run %t
2 // RUN: %clang_dfsan -mllvm -dfsan-args-abi %s -o %t && %run %t
3
4 // Tests that labels are propagated through computation and that union labels
5 // are properly created.
6
7 #include <sanitizer/dfsan_interface.h>
8 #include <assert.h>
9
main(void)10 int main(void) {
11 assert(dfsan_union(0, 0) == 0);
12
13 int i = 1;
14 dfsan_label i_label = dfsan_create_label("i", 0);
15 dfsan_set_label(i_label, &i, sizeof(i));
16
17 int j = 2;
18 dfsan_label j_label = dfsan_create_label("j", 0);
19 dfsan_set_label(j_label, &j, sizeof(j));
20
21 int k = 3;
22 dfsan_label k_label = dfsan_create_label("k", 0);
23 dfsan_set_label(k_label, &k, sizeof(k));
24
25 int k2 = 4;
26 dfsan_set_label(k_label, &k2, sizeof(k2));
27
28 dfsan_label ij_label = dfsan_get_label(i + j);
29 assert(dfsan_has_label(ij_label, i_label));
30 assert(dfsan_has_label(ij_label, j_label));
31 assert(!dfsan_has_label(ij_label, k_label));
32 // Test uniquing.
33 assert(dfsan_union(i_label, j_label) == ij_label);
34 assert(dfsan_union(j_label, i_label) == ij_label);
35
36 dfsan_label ijk_label = dfsan_get_label(i + j + k);
37 assert(dfsan_has_label(ijk_label, i_label));
38 assert(dfsan_has_label(ijk_label, j_label));
39 assert(dfsan_has_label(ijk_label, k_label));
40
41 assert(dfsan_get_label(k + k2) == k_label);
42
43 struct { int i, j; } s = { i, j };
44 assert(dfsan_read_label(&s, sizeof(s)) == ij_label);
45
46 return 0;
47 }
48