Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / msan / dtor-member.cpp
blob6092c8a3a3fddcee723d38db2c2113815d035be9
1 // RUN: %clangxx_msan %s -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && %run %t >%t.out 2>&1
2 // RUN: FileCheck %s < %t.out
4 // RUN: %clangxx_msan %s -O1 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && %run %t >%t.out 2>&1
5 // RUN: FileCheck %s < %t.out
7 // RUN: %clangxx_msan %s -O2 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && %run %t >%t.out 2>&1
8 // RUN: FileCheck %s < %t.out
10 // RUN: %clangxx_msan %s -fsanitize=memory -fno-sanitize-memory-use-after-dtor -o %t && %run %t >%t.out 2>&1
11 // RUN: FileCheck %s --check-prefix=CHECK-NO-FLAG < %t.out
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
16 #include <sanitizer/msan_interface.h>
17 #include <assert.h>
18 #include <stdio.h>
19 #include <new>
21 struct Simple {
22 int x_;
23 Simple() {
24 x_ = 5;
26 ~Simple() { }
29 int main() {
30 unsigned long buf[1];
31 assert(sizeof(Simple) <= sizeof(buf));
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();
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
47 return 0;