223
|
1 // RUN: %clang_dfsan %s -O1 -o %t && %run %t
|
221
|
2 // RUN: %clang_dfsan %s -O0 -DO0 -o %t && %run %t
|
|
3
|
|
4 #include <assert.h>
|
|
5 #include <sanitizer/dfsan_interface.h>
|
|
6
|
|
7 typedef struct Pair {
|
|
8 int i;
|
|
9 char *ptr;
|
|
10 } Pair;
|
|
11
|
|
12 __attribute__((noinline))
|
|
13 Pair make_pair(int i, char *ptr) {
|
|
14 Pair pair;
|
|
15 pair.i = i;
|
|
16 pair.ptr = ptr;
|
|
17 return pair;
|
|
18 }
|
|
19
|
|
20 __attribute__((noinline))
|
|
21 Pair copy_pair1(const Pair *pair0) {
|
|
22 Pair pair;
|
|
23 pair.i = pair0->i;
|
|
24 pair.ptr = pair0->ptr;
|
|
25 return pair;
|
|
26 }
|
|
27
|
|
28 __attribute__((noinline))
|
|
29 Pair copy_pair2(const Pair pair0) {
|
|
30 Pair pair;
|
|
31 pair.i = pair0.i;
|
|
32 pair.ptr = pair0.ptr;
|
|
33 return pair;
|
|
34 }
|
|
35
|
|
36 int main(void) {
|
|
37 int i = 1;
|
|
38 char *ptr = NULL;
|
|
39 dfsan_label i_label = 1;
|
|
40 dfsan_label ptr_label = 2;
|
|
41 dfsan_set_label(i_label, &i, sizeof(i));
|
|
42 dfsan_set_label(ptr_label, &ptr, sizeof(ptr));
|
|
43
|
|
44 Pair pair1 = make_pair(i, ptr);
|
|
45 int i1 = pair1.i;
|
|
46 char *ptr1 = pair1.ptr;
|
|
47
|
|
48 dfsan_label i1_label = dfsan_read_label(&i1, sizeof(i1));
|
|
49 dfsan_label ptr1_label = dfsan_read_label(&ptr1, sizeof(ptr1));
|
223
|
50 #if defined(O0)
|
221
|
51 assert(i1_label == (i_label | ptr_label));
|
|
52 assert(ptr1_label == (i_label | ptr_label));
|
|
53 #else
|
|
54 assert(i1_label == i_label);
|
|
55 assert(ptr1_label == ptr_label);
|
|
56 #endif
|
|
57
|
|
58 Pair pair2 = copy_pair1(&pair1);
|
|
59 int i2 = pair2.i;
|
|
60 char *ptr2 = pair2.ptr;
|
|
61
|
|
62 dfsan_label i2_label = dfsan_read_label(&i2, sizeof(i2));
|
|
63 dfsan_label ptr2_label = dfsan_read_label(&ptr2, sizeof(ptr2));
|
223
|
64 #if defined(O0)
|
221
|
65 assert(i2_label == (i_label | ptr_label));
|
|
66 assert(ptr2_label == (i_label | ptr_label));
|
|
67 #else
|
|
68 assert(i2_label == i_label);
|
|
69 assert(ptr2_label == ptr_label);
|
|
70 #endif
|
|
71
|
|
72 Pair pair3 = copy_pair2(pair1);
|
|
73 int i3 = pair3.i;
|
|
74 char *ptr3 = pair3.ptr;
|
|
75
|
|
76 dfsan_label i3_label = dfsan_read_label(&i3, sizeof(i3));
|
|
77 dfsan_label ptr3_label = dfsan_read_label(&ptr3, sizeof(ptr3));
|
223
|
78 #if defined(O0)
|
221
|
79 assert(i3_label == (i_label | ptr_label));
|
|
80 assert(ptr3_label == (i_label | ptr_label));
|
|
81 #else
|
|
82 assert(i3_label == i_label);
|
|
83 assert(ptr3_label == ptr_label);
|
|
84 #endif
|
|
85
|
|
86
|
|
87 return 0;
|
|
88 }
|