1 // RUN: %clang_dfsan %s -O1 -o %t && %run %t
2 // RUN: %clang_dfsan %s -O0 -DO0 -o %t && %run %t
5 #include <sanitizer/dfsan_interface.h>
12 __attribute__((noinline
))
13 Pair
make_pair(int i
, char *ptr
) {
20 __attribute__((noinline
))
21 Pair
copy_pair1(const Pair
*pair0
) {
24 pair
.ptr
= pair0
->ptr
;
28 __attribute__((noinline
))
29 Pair
copy_pair2(const Pair pair0
) {
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
));
44 Pair pair1
= make_pair(i
, ptr
);
46 char *ptr1
= pair1
.ptr
;
48 dfsan_label i1_label
= dfsan_read_label(&i1
, sizeof(i1
));
49 dfsan_label ptr1_label
= dfsan_read_label(&ptr1
, sizeof(ptr1
));
51 assert(i1_label
== (i_label
| ptr_label
));
52 assert(ptr1_label
== (i_label
| ptr_label
));
54 assert(i1_label
== i_label
);
55 assert(ptr1_label
== ptr_label
);
58 Pair pair2
= copy_pair1(&pair1
);
60 char *ptr2
= pair2
.ptr
;
62 dfsan_label i2_label
= dfsan_read_label(&i2
, sizeof(i2
));
63 dfsan_label ptr2_label
= dfsan_read_label(&ptr2
, sizeof(ptr2
));
65 assert(i2_label
== (i_label
| ptr_label
));
66 assert(ptr2_label
== (i_label
| ptr_label
));
68 assert(i2_label
== i_label
);
69 assert(ptr2_label
== ptr_label
);
72 Pair pair3
= copy_pair2(pair1
);
74 char *ptr3
= pair3
.ptr
;
76 dfsan_label i3_label
= dfsan_read_label(&i3
, sizeof(i3
));
77 dfsan_label ptr3_label
= dfsan_read_label(&ptr3
, sizeof(ptr3
));
79 assert(i3_label
== (i_label
| ptr_label
));
80 assert(ptr3_label
== (i_label
| ptr_label
));
82 assert(i3_label
== i_label
);
83 assert(ptr3_label
== ptr_label
);