| 1 | // RUN: %clangxx_msan %s -O0 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && %run %t >%t.out 2>&1 |
| 2 | // RUN: %clangxx_msan %s -O1 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && %run %t >%t.out 2>&1 |
| 3 | // RUN: %clangxx_msan %s -O2 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && %run %t >%t.out 2>&1 |
| 4 | |
| 5 | #include <sanitizer/msan_interface.h> |
| 6 | #include <assert.h> |
| 7 | |
| 8 | struct Base { |
| 9 | int x; |
| 10 | Base() { x = 5; } |
| 11 | virtual ~Base() {} |
| 12 | }; |
| 13 | |
| 14 | struct Derived : public Base { |
| 15 | int y; |
| 16 | Derived() { y = 10; } |
| 17 | ~Derived() {} |
| 18 | }; |
| 19 | |
| 20 | int main() { |
| 21 | Derived *d = new Derived(); |
| 22 | d->~Derived(); |
| 23 | |
| 24 | // Verify that local pointer is unpoisoned, and that the object's |
| 25 | // members are. |
| 26 | assert(__msan_test_shadow(&d, sizeof(d)) == -1); |
| 27 | assert(__msan_test_shadow(&d->x, sizeof(d->x)) != -1); |
| 28 | assert(__msan_test_shadow(&d->y, sizeof(d->y)) != -1); |
| 29 | |
| 30 | Base *b = new Derived(); |
| 31 | b->~Base(); |
| 32 | |
| 33 | // Verify that local pointer is unpoisoned, and that the object's |
| 34 | // members are. |
| 35 | assert(__msan_test_shadow(&b, sizeof(b)) == -1); |
| 36 | assert(__msan_test_shadow(&b->x, sizeof(b->x)) != -1); |
| 37 | |
| 38 | return 0; |
| 39 | } |
| 40 | |