xref: /aosp_15_r20/external/compiler-rt/test/msan/dtor-trivial.cpp (revision 7c3d14c8b49c529e04be81a3ce6f5cc23712e4c6)
1*7c3d14c8STreehugger Robot // 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*7c3d14c8STreehugger Robot 
3*7c3d14c8STreehugger Robot // 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*7c3d14c8STreehugger Robot 
5*7c3d14c8STreehugger Robot // 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*7c3d14c8STreehugger Robot 
7*7c3d14c8STreehugger Robot // TODO Success pending on resolution of
8*7c3d14c8STreehugger Robot // https://github.com/google/sanitizers/issues/596
9*7c3d14c8STreehugger Robot 
10*7c3d14c8STreehugger Robot // XFAIL: *
11*7c3d14c8STreehugger Robot 
12*7c3d14c8STreehugger Robot #include <assert.h>
13*7c3d14c8STreehugger Robot #include <sanitizer/msan_interface.h>
14*7c3d14c8STreehugger Robot 
15*7c3d14c8STreehugger Robot template <class T> class Vector {
16*7c3d14c8STreehugger Robot  public:
17*7c3d14c8STreehugger Robot   int size;
~Vector()18*7c3d14c8STreehugger Robot   ~Vector() {}
19*7c3d14c8STreehugger Robot };
20*7c3d14c8STreehugger Robot 
21*7c3d14c8STreehugger Robot struct NonTrivial {
22*7c3d14c8STreehugger Robot   int a;
23*7c3d14c8STreehugger Robot   Vector<int> v;
24*7c3d14c8STreehugger Robot };
25*7c3d14c8STreehugger Robot 
26*7c3d14c8STreehugger Robot struct Trivial {
27*7c3d14c8STreehugger Robot   int a;
28*7c3d14c8STreehugger Robot   int b;
29*7c3d14c8STreehugger Robot };
30*7c3d14c8STreehugger Robot 
main()31*7c3d14c8STreehugger Robot int main() {
32*7c3d14c8STreehugger Robot   NonTrivial *nt = new NonTrivial();
33*7c3d14c8STreehugger Robot   nt->~NonTrivial();
34*7c3d14c8STreehugger Robot   assert(__msan_test_shadow(nt, sizeof(*nt)) != -1);
35*7c3d14c8STreehugger Robot 
36*7c3d14c8STreehugger Robot   Trivial *t = new Trivial();
37*7c3d14c8STreehugger Robot   t->~Trivial();
38*7c3d14c8STreehugger Robot   assert(__msan_test_shadow(t, sizeof(*t)) != -1);
39*7c3d14c8STreehugger Robot 
40*7c3d14c8STreehugger Robot   return 0;
41*7c3d14c8STreehugger Robot }
42