[analyzer] Show paths for destructor calls.

This modifies BugReporter and friends to handle CallEnter and CallExitEnd
program points that came from implicit call CFG nodes (read: destructors).

This required some extra handling for nested implicit calls. For example,
the added multiple-inheritance test case has a call graph that looks like this:

testMultipleInheritance3
  ~MultipleInheritance
    ~SmartPointer
    ~Subclass
      ~SmartPointer
        ***bug here***

In this case we correctly notice that we started in an inlined function
when we reach the CallEnter program point for the second ~SmartPointer.
However, when we reach the next CallEnter (for ~Subclass), we were
accidentally re-using the inner ~SmartPointer call in the diagnostics.

Rather than guess if we saw the corresponding CallExitEnd based on the
contents of the active path, we now just ask the PathDiagnostic if there's
any known stack before popping off the top path.

(A similar issue could have occured without multiple inheritance, but there
wasn't a test case for it.)

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@160804 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/test/Analysis/dtor.cpp b/test/Analysis/dtor.cpp
index 5a14f30..8d67f78 100644
--- a/test/Analysis/dtor.cpp
+++ b/test/Analysis/dtor.cpp
@@ -34,3 +34,72 @@
   }
   *mem = 0; // expected-warning{{Use of memory after it is freed}}
 }
+
+
+void doSomething();
+void testSmartPointer2() {
+  char *mem = (char*)malloc(4);
+  {
+    SmartPointer Deleter(mem);
+    // Remove dead bindings...
+    doSomething();
+    // destructor called here
+  }
+  *mem = 0; // expected-warning{{Use of memory after it is freed}}
+}
+
+
+class Subclass : public SmartPointer {
+public:
+  Subclass(void *x) : SmartPointer(x) {}
+};
+
+void testSubclassSmartPointer() {
+  char *mem = (char*)malloc(4);
+  {
+    Subclass Deleter(mem);
+    // Remove dead bindings...
+    doSomething();
+    // destructor called here
+  }
+  *mem = 0; // expected-warning{{Use of memory after it is freed}}
+}
+
+
+class MultipleInheritance : public Subclass, public SmartPointer {
+public:
+  MultipleInheritance(void *a, void *b) : Subclass(a), SmartPointer(b) {}
+};
+
+void testMultipleInheritance1() {
+  char *mem = (char*)malloc(4);
+  {
+    MultipleInheritance Deleter(mem, 0);
+    // Remove dead bindings...
+    doSomething();
+    // destructor called here
+  }
+  *mem = 0; // expected-warning{{Use of memory after it is freed}}
+}
+
+void testMultipleInheritance2() {
+  char *mem = (char*)malloc(4);
+  {
+    MultipleInheritance Deleter(0, mem);
+    // Remove dead bindings...
+    doSomething();
+    // destructor called here
+  }
+  *mem = 0; // expected-warning{{Use of memory after it is freed}}
+}
+
+void testMultipleInheritance3() {
+  char *mem = (char*)malloc(4);
+  {
+    MultipleInheritance Deleter(mem, mem);
+    // Remove dead bindings...
+    doSomething();
+    // destructor called here
+    // expected-warning@25 {{Attempt to free released memory}}
+  }
+}