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 // 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 3*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 4*7c3d14c8STreehugger Robot 5*7c3d14c8STreehugger Robot #include <sanitizer/msan_interface.h> 6*7c3d14c8STreehugger Robot #include <assert.h> 7*7c3d14c8STreehugger Robot 8*7c3d14c8STreehugger Robot struct Base { 9*7c3d14c8STreehugger Robot int x; BaseBase10*7c3d14c8STreehugger Robot Base() { x = 5; } ~BaseBase11*7c3d14c8STreehugger Robot virtual ~Base() {} 12*7c3d14c8STreehugger Robot }; 13*7c3d14c8STreehugger Robot 14*7c3d14c8STreehugger Robot struct Derived : public Base { 15*7c3d14c8STreehugger Robot int y; DerivedDerived16*7c3d14c8STreehugger Robot Derived() { y = 10; } ~DerivedDerived17*7c3d14c8STreehugger Robot ~Derived() {} 18*7c3d14c8STreehugger Robot }; 19*7c3d14c8STreehugger Robot main()20*7c3d14c8STreehugger Robotint main() { 21*7c3d14c8STreehugger Robot Derived *d = new Derived(); 22*7c3d14c8STreehugger Robot d->~Derived(); 23*7c3d14c8STreehugger Robot 24*7c3d14c8STreehugger Robot // Verify that local pointer is unpoisoned, and that the object's 25*7c3d14c8STreehugger Robot // members are. 26*7c3d14c8STreehugger Robot assert(__msan_test_shadow(&d, sizeof(d)) == -1); 27*7c3d14c8STreehugger Robot assert(__msan_test_shadow(&d->x, sizeof(d->x)) != -1); 28*7c3d14c8STreehugger Robot assert(__msan_test_shadow(&d->y, sizeof(d->y)) != -1); 29*7c3d14c8STreehugger Robot 30*7c3d14c8STreehugger Robot Base *b = new Derived(); 31*7c3d14c8STreehugger Robot b->~Base(); 32*7c3d14c8STreehugger Robot 33*7c3d14c8STreehugger Robot // Verify that local pointer is unpoisoned, and that the object's 34*7c3d14c8STreehugger Robot // members are. 35*7c3d14c8STreehugger Robot assert(__msan_test_shadow(&b, sizeof(b)) == -1); 36*7c3d14c8STreehugger Robot assert(__msan_test_shadow(&b->x, sizeof(b->x)) != -1); 37*7c3d14c8STreehugger Robot 38*7c3d14c8STreehugger Robot return 0; 39*7c3d14c8STreehugger Robot } 40