annotate compiler-rt/test/dfsan/propagate.c @ 222:81f6424ef0e3 llvm-original

LLVM original branch
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sun, 18 Jul 2021 22:10:01 +0900
parents 79ff65ed7e25
children 5f17cb93ff66
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 // RUN: %clang_dfsan %s -o %t && %run %t
anatofuz
parents:
diff changeset
2 // RUN: %clang_dfsan -mllvm -dfsan-args-abi %s -o %t && %run %t
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
3 //
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
4 // REQUIRES: x86_64-target-arch
150
anatofuz
parents:
diff changeset
5
anatofuz
parents:
diff changeset
6 // Tests that labels are propagated through computation and that union labels
anatofuz
parents:
diff changeset
7 // are properly created.
anatofuz
parents:
diff changeset
8
anatofuz
parents:
diff changeset
9 #include <sanitizer/dfsan_interface.h>
anatofuz
parents:
diff changeset
10 #include <assert.h>
anatofuz
parents:
diff changeset
11
anatofuz
parents:
diff changeset
12 int main(void) {
anatofuz
parents:
diff changeset
13 assert(dfsan_union(0, 0) == 0);
anatofuz
parents:
diff changeset
14
anatofuz
parents:
diff changeset
15 int i = 1;
anatofuz
parents:
diff changeset
16 dfsan_label i_label = dfsan_create_label("i", 0);
anatofuz
parents:
diff changeset
17 dfsan_set_label(i_label, &i, sizeof(i));
anatofuz
parents:
diff changeset
18
anatofuz
parents:
diff changeset
19 int j = 2;
anatofuz
parents:
diff changeset
20 dfsan_label j_label = dfsan_create_label("j", 0);
anatofuz
parents:
diff changeset
21 dfsan_set_label(j_label, &j, sizeof(j));
anatofuz
parents:
diff changeset
22
anatofuz
parents:
diff changeset
23 int k = 3;
anatofuz
parents:
diff changeset
24 dfsan_label k_label = dfsan_create_label("k", 0);
anatofuz
parents:
diff changeset
25 dfsan_set_label(k_label, &k, sizeof(k));
anatofuz
parents:
diff changeset
26
anatofuz
parents:
diff changeset
27 int k2 = 4;
anatofuz
parents:
diff changeset
28 dfsan_set_label(k_label, &k2, sizeof(k2));
anatofuz
parents:
diff changeset
29
anatofuz
parents:
diff changeset
30 dfsan_label ij_label = dfsan_get_label(i + j);
anatofuz
parents:
diff changeset
31 assert(dfsan_has_label(ij_label, i_label));
anatofuz
parents:
diff changeset
32 assert(dfsan_has_label(ij_label, j_label));
anatofuz
parents:
diff changeset
33 assert(!dfsan_has_label(ij_label, k_label));
anatofuz
parents:
diff changeset
34 // Test uniquing.
anatofuz
parents:
diff changeset
35 assert(dfsan_union(i_label, j_label) == ij_label);
anatofuz
parents:
diff changeset
36 assert(dfsan_union(j_label, i_label) == ij_label);
anatofuz
parents:
diff changeset
37
anatofuz
parents:
diff changeset
38 dfsan_label ijk_label = dfsan_get_label(i + j + k);
anatofuz
parents:
diff changeset
39 assert(dfsan_has_label(ijk_label, i_label));
anatofuz
parents:
diff changeset
40 assert(dfsan_has_label(ijk_label, j_label));
anatofuz
parents:
diff changeset
41 assert(dfsan_has_label(ijk_label, k_label));
anatofuz
parents:
diff changeset
42
anatofuz
parents:
diff changeset
43 assert(dfsan_get_label(k + k2) == k_label);
anatofuz
parents:
diff changeset
44
anatofuz
parents:
diff changeset
45 struct { int i, j; } s = { i, j };
anatofuz
parents:
diff changeset
46 assert(dfsan_read_label(&s, sizeof(s)) == ij_label);
anatofuz
parents:
diff changeset
47
anatofuz
parents:
diff changeset
48 return 0;
anatofuz
parents:
diff changeset
49 }