blob: 233561e4e0721dbb94ac417d07da0fcafcb00966 [file] [log] [blame]
Evgeniy Stepanov7cacbe42015-07-14 00:34:50 +00001// Test -fsanitize-memory-use-after-dtor
2// RUN: %clang_cc1 -fsanitize=memory -fsanitize-memory-use-after-dtor -triple=x86_64-pc-linux -emit-llvm -o - %s | FileCheck %s
Naomi Musgraved3ec7c32015-07-15 22:57:10 +00003// RUN: %clang_cc1 -fsanitize=memory -triple=x86_64-pc-linux -emit-llvm -o - %s | FileCheck %s -check-prefix=NO-DTOR-CHECK
4
5// RUN: %clang_cc1 -std=c++11 -fsanitize=memory -fsanitize-memory-use-after-dtor -triple=x86_64-pc-linux -emit-llvm -o - %s | FileCheck %s -check-prefix=STD11
6// RUN: %clang_cc1 -std=c++11 -fsanitize=memory -triple=x86_64-pc-linux -emit-llvm -o - %s | FileCheck %s -check-prefix=NO-DTOR-STD11-CHECK
Evgeniy Stepanov7cacbe42015-07-14 00:34:50 +00007
8struct Simple {
9 ~Simple() {}
10};
11Simple s;
12// Simple internal member is poisoned by compiler-generated dtor
13// CHECK-LABEL: @_ZN6SimpleD2Ev
14// CHECK: call void @__sanitizer_dtor_callback
15// CHECK: ret void
16
17// Compiling without the flag does not generate member-poisoning dtor
Naomi Musgraved3ec7c32015-07-15 22:57:10 +000018// NO-DTOR-CHECK-LABEL: @_ZN6SimpleD2Ev
19// NO-DTOR-CHECK-NOT: call void @__sanitizer_dtor_callback
20// NO-DTOR-CHECK: ret void
21
22
23struct Inlined {
24 inline ~Inlined() {}
25};
26Inlined in;
27// Dtor that is inlined where invoked poisons object
28// CHECK-LABEL: @_ZN7InlinedD2Ev
29// CHECK: call void @__sanitizer_dtor_callback
30// CHECK: ret void
31
32// Compiling without the flag does not generate member-poisoning dtor
33// NO-DTOR-CHECK-LABEL: @_ZN7InlinedD2Ev
34// NO-DTOR-CHECK-NOT: call void @__sanitizer_dtor_callback
35// NO-DTOR-CHECK: ret void
36
37
38struct Defaulted_Trivial {
39 ~Defaulted_Trivial() = default;
40};
41int main() {
42 Defaulted_Trivial def_trivial;
43}
44// The compiler is explicitly signalled to handle object cleanup.
45// No complex member attributes ensures that the compiler destroys
46// the memory inline. However, it must still poison this memory.
47// STD11-CHECK-LABEL: alloca %struct.Defaulted_Trivial
48// STD11: call void @__sanitizer_dtor_callback
49// STD11: ret void
50
51// Compiling without the flag does not generate member-poisoning dtor
52// NO-DTOR-STD11-CHECK-LABEL: alloca %struct.Defaulted_Trivial
53// NO-DTOR-STD11-CHECK-NOT: call void @__sanitizer_dtor_callback
54// NO-DTOR-STD11-CHECK: ret void
55
56
57struct Defaulted_Non_Trivial {
58 Simple s;
59 ~Defaulted_Non_Trivial() = default;
60};
61Defaulted_Non_Trivial def_non_trivial;
62// Explicitly compiler-generated dtor poisons object.
63// By including a Simple member in the struct, the compiler is
64// forced to generate a non-trivial destructor..
65// STD11-CHECK-LABEL: @_ZN21Defaulted_Non_TrivialD2Ev
66// STD11: call void @__sanitizer_dtor_callback
67// STD11: ret void
68
69// Compiling without the flag does not generate member-poisoning dtor
70// NO-DTOR-STD11-CHECK-LABEL: @_ZN21Defaulted_Non_TrivialD2Ev
71// NO-DTOR-STD11-CHECK-NOT: call void @__sanitizer_dtor_callback
72// NO-DTOR-STD11-CHECK: ret void