Fix a bug in my previous patch: If we are not doing a virtual call because
the member expression is qualified, call the method specified in the code,
not the most derived one we can find.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@159219 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CGExprCXX.cpp b/lib/CodeGen/CGExprCXX.cpp
index f35287d..372eb54 100644
--- a/lib/CodeGen/CGExprCXX.cpp
+++ b/lib/CodeGen/CGExprCXX.cpp
@@ -240,6 +240,8 @@
           MD->isVirtual() &&
           ME->hasQualifier())
         Callee = BuildAppleKextVirtualCall(MD, ME->getQualifier(), Ty);
+      else if (ME->hasQualifier())
+        Callee = CGM.GetAddrOfFunction(GlobalDecl(Dtor, Dtor_Complete), Ty);
       else {
         const CXXMethodDecl *DM =
           Dtor->getCorrespondingMethodInClass(MostDerivedClassDecl);
@@ -258,6 +260,8 @@
         MD->isVirtual() &&
         ME->hasQualifier())
       Callee = BuildAppleKextVirtualCall(MD, ME->getQualifier(), Ty);
+    else if (ME->hasQualifier())
+      Callee = CGM.GetAddrOfFunction(MD, Ty);
     else {
       const CXXMethodDecl *DerivedMethod =
         MD->getCorrespondingMethodInClass(MostDerivedClassDecl);
diff --git a/test/CodeGenCXX/devirtualize-virtual-function-calls.cpp b/test/CodeGenCXX/devirtualize-virtual-function-calls.cpp
index 5eede66..a0b6e8c 100644
--- a/test/CodeGenCXX/devirtualize-virtual-function-calls.cpp
+++ b/test/CodeGenCXX/devirtualize-virtual-function-calls.cpp
@@ -53,3 +53,21 @@
   B().h().f();
 }
 
+namespace test2 {
+  struct foo {
+    virtual void f();
+    virtual ~foo();
+  };
+
+  struct bar : public foo {
+    virtual void f();
+    virtual ~bar();
+  };
+
+  void f(bar *b) {
+    // CHECK: call void @_ZN5test23foo1fEv
+    // CHECK: call void @_ZN5test23fooD1Ev
+    b->foo::f();
+    b->foo::~foo();
+  }
+}