Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / dfsan / propagate.c
blob6a16058ca4de9d5129afe0159408c80cf394cc2b
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>
7 #include <assert.h>
9 int main(void) {
10 assert(dfsan_union(0, 0) == 0);
12 int i = 1;
13 dfsan_label i_label = 1;
14 dfsan_set_label(i_label, &i, sizeof(i));
16 int j = 2;
17 dfsan_label j_label = 2;
18 dfsan_set_label(j_label, &j, sizeof(j));
20 int k = 3;
21 dfsan_label k_label = 4;
22 dfsan_set_label(k_label, &k, sizeof(k));
24 int k2 = 4;
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));
31 // Test uniquing.
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);
45 return 0;