Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / msan / dtor-bit-fields.cpp
blob6074ed50b4781ac586c21435fbb951139a57acd5
1 // RUN: %clangxx_msan %s -O0 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && %run %t
3 // RUN: %clangxx_msan %s -O1 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && %run %t
5 // RUN: %clangxx_msan %s -O2 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && %run %t
7 #include <sanitizer/msan_interface.h>
8 #include <assert.h>
10 // TODO: remove empty dtors when msan use-after-dtor poisons
11 // for trivial classes with undeclared dtors
13 // 24 bytes total
14 struct Packed {
15 // Packed into 4 bytes
16 unsigned int a : 1;
17 unsigned int b : 1;
18 // Force alignment to next 4 bytes
19 unsigned int : 0;
20 unsigned int c : 1;
21 // Force alignment, 8 more bytes
22 double d = 5.0;
23 // 4 bytes
24 unsigned int e : 1;
25 ~Packed() {}
28 // 1 byte total
29 struct Empty {
30 unsigned int : 0;
31 ~Empty() {}
34 // 4 byte total
35 struct Simple {
36 unsigned int a : 1;
37 ~Simple() {}
40 struct Anon {
41 unsigned int a : 1;
42 unsigned int b : 2;
43 unsigned int : 0;
44 unsigned int c : 1;
45 ~Anon() {}
48 int main() {
49 Packed *p = new Packed();
50 p->~Packed();
51 for (int i = 0; i < 4; i++)
52 assert(__msan_test_shadow(((char*)p) + i, sizeof(char)) != -1);
53 assert(__msan_test_shadow(&p->d, sizeof(double)) != -1);
54 assert(__msan_test_shadow(((char*)(&p->d)) + sizeof(double), sizeof(char)) !=
55 -1);
57 Empty *e = new Empty();
58 e->~Empty();
59 assert(__msan_test_shadow(e, sizeof(*e)) != -1);
61 Simple *s = new Simple();
62 s->~Simple();
63 assert(__msan_test_shadow(s, sizeof(*s)) != -1);
65 Anon *a = new Anon();
66 a->~Anon();
67 assert(__msan_test_shadow(a, sizeof(*a)) != -1);
69 return 0;