49 lines · cpp
1// RUN: %clangxx_msan %s -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && %run %t >%t.out 2>&12// RUN: FileCheck %s < %t.out3 4// RUN: %clangxx_msan %s -O1 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && %run %t >%t.out 2>&15// RUN: FileCheck %s < %t.out6 7// RUN: %clangxx_msan %s -O2 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && %run %t >%t.out 2>&18// RUN: FileCheck %s < %t.out9 10// RUN: %clangxx_msan %s -fsanitize=memory -fno-sanitize-memory-use-after-dtor -o %t && %run %t >%t.out 2>&111// RUN: FileCheck %s --check-prefix=CHECK-NO-FLAG < %t.out12 13// RUN: %clangxx_msan -fsanitize=memory -fsanitize-memory-use-after-dtor %s -o %t && env MSAN_OPTIONS=poison_in_dtor=0 %run %t >%t.out 2>&114// RUN: FileCheck %s --check-prefix=CHECK-NO-FLAG < %t.out15 16#include <sanitizer/msan_interface.h>17#include <assert.h>18#include <stdio.h>19#include <new>20 21struct Simple {22 int x_;23 Simple() {24 x_ = 5;25 }26 ~Simple() { }27};28 29int 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 the34 // memory location &buf. Since objects made in this way must be explicitly35 // destroyed, there are no implicit calls inserted that would interfere with36 // 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 else43 printf("s is not poisoned\n");44 // CHECK: s is poisoned45 // CHECK-NO-FLAG: s is not poisoned46 47 return 0;48}49