1 // Defines diamond multiple inheritance structure
8 // RUN: %clangxx_msan %s -O0 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && %run %t >%t.out 2>&1
10 // RUN: %clangxx_msan %s -O1 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && %run %t >%t.out 2>&1
12 // RUN: %clangxx_msan %s -O2 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && %run %t >%t.out 2>&1
14 #include <sanitizer/msan_interface.h>
27 assert(__msan_test_shadow(&this->x
, sizeof(this->x
) == -1));
28 // Memory owned by subclasses is poisoned.
29 assert(__msan_test_shadow(temp_y
, sizeof(*temp_y
)) != -1);
30 assert(__msan_test_shadow(temp_z
, sizeof(*temp_z
)) != -1);
31 assert(__msan_test_shadow(temp_w
, sizeof(*temp_w
)) != -1);
35 struct B
: virtual public A
{
40 assert(__msan_test_shadow(&this->y
, sizeof(this->y
)) == -1);
41 // Memory accessible via vtable still reachable.
42 assert(__msan_test_shadow(&this->x
, sizeof(this->x
)) == -1);
43 // Memory in sibling and subclass is poisoned.
44 assert(__msan_test_shadow(temp_z
, sizeof(*temp_z
)) != -1);
45 assert(__msan_test_shadow(temp_w
, sizeof(*temp_w
)) != -1);
49 struct C
: virtual public A
{
54 assert(__msan_test_shadow(&this->z
, sizeof(this->z
)) == -1);
55 // Memory accessible via vtable still reachable.
56 assert(__msan_test_shadow(&this->x
, sizeof(this->x
)) == -1);
57 // Sibling class is unpoisoned.
58 assert(__msan_test_shadow(temp_y
, sizeof(*temp_y
)) == -1);
59 // Memory in subclasses is poisoned.
60 assert(__msan_test_shadow(temp_w
, sizeof(*temp_w
)) != -1);
64 class Derived
: public B
, public C
{
69 assert(__msan_test_shadow(&this->x
, sizeof(this->x
)) == -1);
70 // Members accessed through the vtable are still accessible.
71 assert(__msan_test_shadow(&this->y
, sizeof(this->y
)) == -1);
72 assert(__msan_test_shadow(&this->z
, sizeof(this->z
)) == -1);
73 assert(__msan_test_shadow(&this->w
, sizeof(this->w
)) == -1);
79 Derived
*d
= new Derived();
81 // Keep track of members inherited from virtual bases,
82 // since the virtual base table is inaccessible after destruction.
88 // Order of destruction: Derived, C, B, A
90 // Verify that local pointer is unpoisoned, and that the object's
92 assert(__msan_test_shadow(&d
, sizeof(d
)) == -1);
93 assert(__msan_test_shadow(temp_x
, sizeof(*temp_x
)) != -1);
94 assert(__msan_test_shadow(temp_y
, sizeof(*temp_y
)) != -1);
95 assert(__msan_test_shadow(temp_z
, sizeof(*temp_z
)) != -1);
96 assert(__msan_test_shadow(temp_w
, sizeof(*temp_w
)) != -1);