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