Index: test/msan/dtor-multiple-inheritance.cc =================================================================== --- /dev/null +++ test/msan/dtor-multiple-inheritance.cc @@ -0,0 +1,71 @@ +// Defines diamond multiple inheritance structure +// A +// / \ +// B C +// \ / +// Derived + +// RUN: %clangxx_msan %s -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t >%t.out 2>&1 + +// 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 + +// 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 + +#include +#include +#include + +struct A { + int x; + A() { + x = 5; + } + virtual ~A() { + printf("~A %p %p %lu\n", this, &this->x, sizeof(x)); + } +}; + +struct B : public virtual A { + int y; + B() { + y = 10; + } + virtual ~B() { + printf("~B %p %p %lu\n", this, &this->y, sizeof(y)); + } +}; + +struct C :public virtual A { + int z; + C() { + z = 15; + } + ~C() { + printf("~C %p %p %lu\n", this, &this->z, sizeof(z)); + } +}; + +struct Derived :public B,C { + int w; + Derived() { + w = 15; + } + ~Derived() { + printf("~D %p %p %lu\n", this, &this->w, sizeof(w)); + } +}; + +int main() { + Derived *d = new Derived(); + d->~Derived(); + + // Verify that local pointer is unpoisoned, and that the object's + // members are. + assert(__msan_test_shadow(&d, sizeof(d)) == -1); + assert(__msan_test_shadow(&d->x, sizeof(d->x)) != -1); + assert(__msan_test_shadow(&d->y, sizeof(d->y)) != -1); + assert(__msan_test_shadow(&d->z, sizeof(d->z)) != -1); + assert(__msan_test_shadow(&d->z, sizeof(d->w)) != -1); + + return 0; +}