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