1 // RUN: %clangxx_msan %s -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && MSAN_OPTIONS=poison_in_dtor=1 not %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 not %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 not %run %t >%t.out 2>&1
8 // RUN: FileCheck %s < %t.out
9
10 // RUN: %clangxx_msan %s -O1 -fsanitize=memory -fsanitize-memory-use-after-dtor -fsanitize-memory-track-origins -o %t && MSAN_OPTIONS=poison_in_dtor=1 not %run %t >%t.out 2>&1
11 // RUN: FileCheck %s --check-prefix=CHECK-ORIGINS < %t.out
12
13 #include <sanitizer/msan_interface.h>
14 #include <assert.h>
15 #include <stdio.h>
16 #include <new>
17
18 struct Simple {
19 int x_;
SimpleSimple20 Simple() {
21 x_ = 5;
22 }
~SimpleSimple23 ~Simple() {
24 x_ += 1;
25 }
26 };
27
main()28 int main() {
29 unsigned long buf[1];
30 assert(sizeof(Simple) <= sizeof(buf));
31
32 Simple *s = new(&buf) Simple();
33 s->~Simple();
34
35 return s->x_;
36
37 // CHECK: WARNING: MemorySanitizer: use-of-uninitialized-value
38 // CHECK: {{#0 0x.* in main.*use-after-dtor.cc:}}[[@LINE-3]]
39
40 // CHECK-ORIGINS: Memory was marked as uninitialized
41 // CHECK-ORIGINS: {{#0 0x.* in __sanitizer_dtor_callback}}
42 // CHECK-ORIGINS: {{#1 0x.* in Simple::~Simple}}
43
44 // CHECK: SUMMARY: MemorySanitizer: use-of-uninitialized-value {{.*main}}
45 }
46