llvm-project
46 строк · 1.2 Кб
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
9int main(void) {
10assert(dfsan_union(0, 0) == 0);
11
12int i = 1;
13dfsan_label i_label = 1;
14dfsan_set_label(i_label, &i, sizeof(i));
15
16int j = 2;
17dfsan_label j_label = 2;
18dfsan_set_label(j_label, &j, sizeof(j));
19
20int k = 3;
21dfsan_label k_label = 4;
22dfsan_set_label(k_label, &k, sizeof(k));
23
24int k2 = 4;
25dfsan_set_label(k_label, &k2, sizeof(k2));
26
27dfsan_label ij_label = dfsan_get_label(i + j);
28assert(dfsan_has_label(ij_label, i_label));
29assert(dfsan_has_label(ij_label, j_label));
30assert(!dfsan_has_label(ij_label, k_label));
31// Test uniquing.
32assert(dfsan_union(i_label, j_label) == ij_label);
33assert(dfsan_union(j_label, i_label) == ij_label);
34
35dfsan_label ijk_label = dfsan_get_label(i + j + k);
36assert(dfsan_has_label(ijk_label, i_label));
37assert(dfsan_has_label(ijk_label, j_label));
38assert(dfsan_has_label(ijk_label, k_label));
39
40assert(dfsan_get_label(k + k2) == k_label);
41
42struct { int i, j; } s = { i, j };
43assert(dfsan_read_label(&s, sizeof(s)) == ij_label);
44
45return 0;
46}
47