1 // 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 2 // RUN: FileCheck %s < %t.out 3 4 // 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 5 // RUN: FileCheck %s < %t.out 6 7 // 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 8 // RUN: FileCheck %s < %t.out 9 10 // RUN: %clangxx_msan %s -fsanitize=memory -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t >%t.out 2>&1 11 // RUN: FileCheck %s --check-prefix=CHECK-NO-FLAG < %t.out 12 13 // RUN: %clangxx_msan -fsanitize=memory -fsanitize-memory-use-after-dtor %s -o %t && MSAN_OPTIONS=poison_in_dtor=0 %run %t >%t.out 2>&1 14 // RUN: FileCheck %s --check-prefix=CHECK-NO-FLAG < %t.out 15 16 #include <sanitizer/msan_interface.h> 17 #include <assert.h> 18 #include <stdio.h> 19 #include <new> 20 21 struct Simple { 22 int x_; 23 Simple() { 24 x_ = 5; 25 } 26 ~Simple() { } 27 }; 28 29 int main() { 30 unsigned long buf[1]; 31 assert(sizeof(Simple) <= sizeof(buf)); 32 33 // The placement new operator forces the object to be constructed in the 34 // memory location &buf. Since objects made in this way must be explicitly 35 // destroyed, there are no implicit calls inserted that would interfere with 36 // test behavior. 37 Simple *s = new(&buf) Simple(); 38 s->~Simple(); 39 40 if (__msan_test_shadow(s, sizeof(*s)) != -1) 41 printf("s is poisoned\n"); 42 else 43 printf("s is not poisoned\n"); 44 // CHECK: s is poisoned 45 // CHECK-NO-FLAG: s is not poisoned 46 47 return 0; 48 } 49