Mercurial > hg > CbC > CbC_llvm
comparison compiler-rt/test/msan/dtor-trivial-class-members.cpp @ 150:1d019706d866
LLVM10
author | anatofuz |
---|---|
date | Thu, 13 Feb 2020 15:10:13 +0900 |
parents | |
children | c4bab56944e8 |
comparison
equal
deleted
inserted
replaced
147:c2174574ed3a | 150:1d019706d866 |
---|---|
1 // RUN: %clangxx_msan %s -O0 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t >%t.out 2>&1 | |
2 | |
3 // RUN: %clangxx_msan %s -O1 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t >%t.out 2>&1 | |
4 | |
5 // RUN: %clangxx_msan %s -O2 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t >%t.out 2>&1 | |
6 | |
7 #include <sanitizer/msan_interface.h> | |
8 #include <assert.h> | |
9 #include <stdio.h> | |
10 | |
11 template <class T> | |
12 class Vector { | |
13 public: | |
14 int size; | |
15 ~Vector() { | |
16 printf("~V %p %lu\n", &size, sizeof(size)); | |
17 assert(__msan_test_shadow(&this->size, sizeof(this->size)) == -1); | |
18 } | |
19 }; | |
20 | |
21 struct Derived { | |
22 int derived_a; | |
23 Vector<int> derived_v1; | |
24 Vector<int> derived_v2; | |
25 double derived_b; | |
26 double derived_c; | |
27 Derived() { | |
28 derived_a = 5; | |
29 derived_v1.size = 1; | |
30 derived_v2.size = 1; | |
31 derived_b = 7; | |
32 derived_c = 10; | |
33 } | |
34 ~Derived() { | |
35 printf("~D %p %p %p %lu\n", &derived_a, &derived_v1, &derived_c, sizeof(*this)); | |
36 assert(__msan_test_shadow(&derived_a, sizeof(derived_a)) == -1); | |
37 assert(__msan_test_shadow(&derived_v1, sizeof(derived_v1)) == -1); | |
38 assert(__msan_test_shadow(&derived_v2, sizeof(derived_v2)) == -1); | |
39 assert(__msan_test_shadow(&derived_b, sizeof(derived_b)) == -1); | |
40 assert(__msan_test_shadow(&derived_c, sizeof(derived_c)) == -1); | |
41 } | |
42 }; | |
43 | |
44 int main() { | |
45 Derived *d = new Derived(); | |
46 d->~Derived(); | |
47 | |
48 assert(__msan_test_shadow(&d->derived_a, sizeof(d->derived_a)) != -1); | |
49 assert(__msan_test_shadow(&d->derived_v1, sizeof(d->derived_v1)) != -1); | |
50 assert(__msan_test_shadow(&d->derived_v2, sizeof(d->derived_v2)) != -1); | |
51 assert(__msan_test_shadow(&d->derived_b, sizeof(d->derived_b)) != -1); | |
52 assert(__msan_test_shadow(&d->derived_c, sizeof(d->derived_c)) != -1); | |
53 | |
54 return 0; | |
55 } |