Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / msan / use-after-dtor.cpp
blobcbd6a1ce40e0cdebdf9fc1b9a8a328662360fcd8
1 // RUN: %clangxx_msan %s -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-UAD
2 // RUN: %clangxx_msan %s -O1 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && not %t 2>&1 | FileCheck %s --check-prefix=CHECK-UAD
3 // RUN: %clangxx_msan %s -O2 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-UAD
4 // RUN: %clangxx_msan %s -O1 -fsanitize=memory -fsanitize-memory-use-after-dtor -fsanitize-memory-track-origins -o %t && not %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK-UAD,CHECK-ORIGINS
5 // RUN: %clangxx_msan %s -fno-sanitize-memory-use-after-dtor -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-UAD-OFF
7 #include <sanitizer/msan_interface.h>
8 #include <assert.h>
9 #include <stdio.h>
10 #include <new>
12 struct Simple {
13 int x_;
14 Simple() {
15 x_ = 5;
17 ~Simple() {
18 x_ += 1;
22 int main() {
23 unsigned long buf[1];
24 assert(sizeof(Simple) <= sizeof(buf));
26 Simple *s = new(&buf) Simple();
27 s->~Simple();
29 fprintf(stderr, "\n"); // Need output to parse for CHECK-UAD-OFF case
30 return s->x_;
32 // CHECK-UAD: WARNING: MemorySanitizer: use-of-uninitialized-value
33 // CHECK-UAD: {{#0 0x.* in main.*use-after-dtor.cpp:}}[[@LINE-3]]
35 // CHECK-ORIGINS: Member fields were destroyed
36 // CHECK-ORIGINS: {{#0 0x.* in __sanitizer_dtor_callback}}
37 // CHECK-ORIGINS: {{#1 0x.* in .*~Simple.*cpp:}}[[@LINE-24]]:
38 // CHECK-ORIGINS: {{#2 0x.* in .*~Simple.*cpp:}}[[@LINE-19]]:
40 // CHECK-UAD: SUMMARY: MemorySanitizer: use-of-uninitialized-value {{.*main}}
41 // CHECK-UAD-OFF-NOT: SUMMARY: MemorySanitizer: use-of-uninitialized-value