summaryrefslogtreecommitdiff
path: root/test/Analysis/dtor.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/Analysis/dtor.cpp')
-rw-r--r--test/Analysis/dtor.cpp78
1 files changed, 76 insertions, 2 deletions
diff --git a/test/Analysis/dtor.cpp b/test/Analysis/dtor.cpp
index 1f45925561c9..f46194599d4e 100644
--- a/test/Analysis/dtor.cpp
+++ b/test/Analysis/dtor.cpp
@@ -1,6 +1,7 @@
-// RUN: %clang_cc1 -analyze -analyzer-checker=core,unix.Malloc,debug.ExprInspection -analyzer-store region -analyzer-ipa=inlining -cfg-add-implicit-dtors -Wno-null-dereference -verify %s
+// RUN: %clang_cc1 -analyze -analyzer-checker=core,unix.Malloc,debug.ExprInspection -analyzer-ipa=inlining -analyzer-config c++-inlining=destructors -Wno-null-dereference -verify %s
void clang_analyzer_eval(bool);
+void clang_analyzer_checkInlined(bool);
class A {
public:
@@ -102,7 +103,7 @@ void testMultipleInheritance3() {
// Remove dead bindings...
doSomething();
// destructor called here
- // expected-warning@27 {{Attempt to free released memory}}
+ // expected-warning@28 {{Attempt to free released memory}}
}
}
@@ -227,3 +228,76 @@ namespace DestructorVirtualCalls {
clang_analyzer_eval(c == 3); // expected-warning{{TRUE}}
}
}
+
+
+namespace DestructorsShouldNotAffectReturnValues {
+ class Dtor {
+ public:
+ ~Dtor() {
+ clang_analyzer_checkInlined(true); // expected-warning{{TRUE}}
+ }
+ };
+
+ void *allocate() {
+ Dtor d;
+ return malloc(4); // no-warning
+ }
+
+ void test() {
+ // At one point we had an issue where the statements inside an
+ // inlined destructor kept us from finding the return statement,
+ // leading the analyzer to believe that the malloc'd memory had leaked.
+ void *p = allocate();
+ free(p); // no-warning
+ }
+}
+
+namespace MultipleInheritanceVirtualDtors {
+ class VirtualDtor {
+ protected:
+ virtual ~VirtualDtor() {
+ clang_analyzer_checkInlined(true); // expected-warning{{TRUE}}
+ }
+ };
+
+ class NonVirtualDtor {
+ protected:
+ ~NonVirtualDtor() {
+ clang_analyzer_checkInlined(true); // expected-warning{{TRUE}}
+ }
+ };
+
+ class SubclassA : public VirtualDtor, public NonVirtualDtor {
+ public:
+ virtual ~SubclassA() {}
+ };
+ class SubclassB : public NonVirtualDtor, public VirtualDtor {
+ public:
+ virtual ~SubclassB() {}
+ };
+
+ void test() {
+ SubclassA a;
+ SubclassB b;
+ }
+}
+
+namespace ExplicitDestructorCall {
+ class VirtualDtor {
+ public:
+ virtual ~VirtualDtor() {
+ clang_analyzer_checkInlined(true); // expected-warning{{TRUE}}
+ }
+ };
+
+ class Subclass : public VirtualDtor {
+ public:
+ virtual ~Subclass() {
+ clang_analyzer_checkInlined(false); // no-warning
+ }
+ };
+
+ void destroy(Subclass *obj) {
+ obj->VirtualDtor::~VirtualDtor();
+ }
+}