annotate compiler-rt/test/msan/dtor-trivial-class-members.cpp @ 222:81f6424ef0e3 llvm-original

LLVM original branch
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sun, 18 Jul 2021 22:10:01 +0900
parents 1d019706d866
children c4bab56944e8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 // RUN: %clangxx_msan %s -O0 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t >%t.out 2>&1
anatofuz
parents:
diff changeset
2
anatofuz
parents:
diff changeset
3 // 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
anatofuz
parents:
diff changeset
4
anatofuz
parents:
diff changeset
5 // 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
anatofuz
parents:
diff changeset
6
anatofuz
parents:
diff changeset
7 #include <sanitizer/msan_interface.h>
anatofuz
parents:
diff changeset
8 #include <assert.h>
anatofuz
parents:
diff changeset
9 #include <stdio.h>
anatofuz
parents:
diff changeset
10
anatofuz
parents:
diff changeset
11 template <class T>
anatofuz
parents:
diff changeset
12 class Vector {
anatofuz
parents:
diff changeset
13 public:
anatofuz
parents:
diff changeset
14 int size;
anatofuz
parents:
diff changeset
15 ~Vector() {
anatofuz
parents:
diff changeset
16 printf("~V %p %lu\n", &size, sizeof(size));
anatofuz
parents:
diff changeset
17 assert(__msan_test_shadow(&this->size, sizeof(this->size)) == -1);
anatofuz
parents:
diff changeset
18 }
anatofuz
parents:
diff changeset
19 };
anatofuz
parents:
diff changeset
20
anatofuz
parents:
diff changeset
21 struct Derived {
anatofuz
parents:
diff changeset
22 int derived_a;
anatofuz
parents:
diff changeset
23 Vector<int> derived_v1;
anatofuz
parents:
diff changeset
24 Vector<int> derived_v2;
anatofuz
parents:
diff changeset
25 double derived_b;
anatofuz
parents:
diff changeset
26 double derived_c;
anatofuz
parents:
diff changeset
27 Derived() {
anatofuz
parents:
diff changeset
28 derived_a = 5;
anatofuz
parents:
diff changeset
29 derived_v1.size = 1;
anatofuz
parents:
diff changeset
30 derived_v2.size = 1;
anatofuz
parents:
diff changeset
31 derived_b = 7;
anatofuz
parents:
diff changeset
32 derived_c = 10;
anatofuz
parents:
diff changeset
33 }
anatofuz
parents:
diff changeset
34 ~Derived() {
anatofuz
parents:
diff changeset
35 printf("~D %p %p %p %lu\n", &derived_a, &derived_v1, &derived_c, sizeof(*this));
anatofuz
parents:
diff changeset
36 assert(__msan_test_shadow(&derived_a, sizeof(derived_a)) == -1);
anatofuz
parents:
diff changeset
37 assert(__msan_test_shadow(&derived_v1, sizeof(derived_v1)) == -1);
anatofuz
parents:
diff changeset
38 assert(__msan_test_shadow(&derived_v2, sizeof(derived_v2)) == -1);
anatofuz
parents:
diff changeset
39 assert(__msan_test_shadow(&derived_b, sizeof(derived_b)) == -1);
anatofuz
parents:
diff changeset
40 assert(__msan_test_shadow(&derived_c, sizeof(derived_c)) == -1);
anatofuz
parents:
diff changeset
41 }
anatofuz
parents:
diff changeset
42 };
anatofuz
parents:
diff changeset
43
anatofuz
parents:
diff changeset
44 int main() {
anatofuz
parents:
diff changeset
45 Derived *d = new Derived();
anatofuz
parents:
diff changeset
46 d->~Derived();
anatofuz
parents:
diff changeset
47
anatofuz
parents:
diff changeset
48 assert(__msan_test_shadow(&d->derived_a, sizeof(d->derived_a)) != -1);
anatofuz
parents:
diff changeset
49 assert(__msan_test_shadow(&d->derived_v1, sizeof(d->derived_v1)) != -1);
anatofuz
parents:
diff changeset
50 assert(__msan_test_shadow(&d->derived_v2, sizeof(d->derived_v2)) != -1);
anatofuz
parents:
diff changeset
51 assert(__msan_test_shadow(&d->derived_b, sizeof(d->derived_b)) != -1);
anatofuz
parents:
diff changeset
52 assert(__msan_test_shadow(&d->derived_c, sizeof(d->derived_c)) != -1);
anatofuz
parents:
diff changeset
53
anatofuz
parents:
diff changeset
54 return 0;
anatofuz
parents:
diff changeset
55 }