blob: 4af26770223f5bc4e833ab38df14814467aecd14 [file] [log] [blame]
Naomi Musgravebb4df942015-08-03 22:53:11 +00001// Test -fsanitize-memory-use-after-dtor
2// RUN: %clang_cc1 -fsanitize=memory -fsanitize-memory-use-after-dtor -std=c++11 -triple=x86_64-pc-linux -emit-llvm -o - %s | FileCheck %s
Naomi Musgravee50cb9b2015-08-13 18:35:11 +00003
4// The no_sanitize_memory attribute, when applied to a destructor,
5// represses emission of sanitizing callback
Naomi Musgravebb4df942015-08-03 22:53:11 +00006
7template <class T> class Vector {
8 public:
Naomi Musgravee50cb9b2015-08-13 18:35:11 +00009 int size;
Naomi Musgravebb4df942015-08-03 22:53:11 +000010 ~Vector() {}
11};
12
13struct No_San {
14 Vector<int> v;
Naomi Musgravee50cb9b2015-08-13 18:35:11 +000015 int x;
Naomi Musgravebb4df942015-08-03 22:53:11 +000016 No_San() { }
Naomi Musgravebb4df942015-08-03 22:53:11 +000017 __attribute__((no_sanitize_memory)) ~No_San() = default;
Naomi Musgravebb4df942015-08-03 22:53:11 +000018};
19
20int main() {
21 No_San *ns = new No_San();
22 ns->~No_San();
23 return 0;
24}
25
26// Repressing the sanitization attribute results in no msan
27// instrumentation of the destructor
28// CHECK: define {{.*}}No_SanD1Ev{{.*}} [[ATTRIBUTE:#[0-9]+]]
Naomi Musgravee50cb9b2015-08-13 18:35:11 +000029// CHECK-NOT: call void {{.*}}sanitizer_dtor_callback
Naomi Musgravebb4df942015-08-03 22:53:11 +000030// CHECK: ret void
31
Naomi Musgravebb4df942015-08-03 22:53:11 +000032// CHECK: define {{.*}}No_SanD2Ev{{.*}} [[ATTRIBUTE:#[0-9]+]]
Naomi Musgravee50cb9b2015-08-13 18:35:11 +000033// CHECK-NOT: call void {{.*}}sanitizer_dtor_callback
34// CHECK: call void {{.*}}VectorIiED2Ev
35// CHECK-NOT: call void {{.*}}sanitizer_dtor_callback
Naomi Musgravebb4df942015-08-03 22:53:11 +000036// CHECK: ret void
37
Naomi Musgravee50cb9b2015-08-13 18:35:11 +000038// CHECK: define {{.*}}VectorIiED2Ev
39// CHECK: call void {{.*}}sanitizer_dtor_callback
40// CHECK: ret void
Naomi Musgravebb4df942015-08-03 22:53:11 +000041
42// When attribute is repressed, the destructor does not emit any tail calls
Naomi Musgravee50cb9b2015-08-13 18:35:11 +000043// CHECK-NOT: attributes [[ATTRIBUTE]] = {{.*}} sanitize_memory