1// RUN: %clangxx_msan %s -O0 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && %run %t >%t.out 2>&1
2
3// RUN: %clangxx_msan %s -O1 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && %run %t >%t.out 2>&1
4
5// RUN: %clangxx_msan %s -O2 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && %run %t >%t.out 2>&1
6
7// TODO Success pending on resolution of
8// https://github.com/google/sanitizers/issues/596
9
10// XFAIL: *
11
12#include <assert.h>
13#include <sanitizer/msan_interface.h>
14
15template <class T> class Vector {
16 public:
17 int size;
18 ~Vector() {}
19};
20
21struct NonTrivial {
22 int a;
23 Vector<int> v;
24};
25
26struct Trivial {
27 int a;
28 int b;
29};
30
31int main() {
32 NonTrivial *nt = new NonTrivial();
33 nt->~NonTrivial();
34 assert(__msan_test_shadow(nt, sizeof(*nt)) != -1);
35
36 Trivial *t = new Trivial();
37 t->~Trivial();
38 assert(__msan_test_shadow(t, sizeof(*t)) != -1);
39
40 return 0;
41}
42

source code of compiler-rt/test/msan/dtor-trivial.cpp