1 // RUN: %clang_dfsan %s -o %t && %run %t
3 // Tests that labels are propagated through computation and that union labels
4 // are properly created.
6 #include <sanitizer/dfsan_interface.h>
10 assert(dfsan_union(0, 0) == 0);
13 dfsan_label i_label
= 1;
14 dfsan_set_label(i_label
, &i
, sizeof(i
));
17 dfsan_label j_label
= 2;
18 dfsan_set_label(j_label
, &j
, sizeof(j
));
21 dfsan_label k_label
= 4;
22 dfsan_set_label(k_label
, &k
, sizeof(k
));
25 dfsan_set_label(k_label
, &k2
, sizeof(k2
));
27 dfsan_label ij_label
= dfsan_get_label(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
));
32 assert(dfsan_union(i_label
, j_label
) == ij_label
);
33 assert(dfsan_union(j_label
, i_label
) == ij_label
);
35 dfsan_label ijk_label
= dfsan_get_label(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
));
40 assert(dfsan_get_label(k
+ k2
) == k_label
);
42 struct { int i
, j
; } s
= { i
, j
};
43 assert(dfsan_read_label(&s
, sizeof(s
)) == ij_label
);