From: Rafael Espindola Date: Tue, 26 Jun 2012 19:18:25 +0000 (+0000) Subject: Fix a bug in my previous patch: If we are not doing a virtual call because X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=12582bdc2e1fca260eb2437d87dab5302c37bab2;p=clang 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 f35287d540..372eb5407c 100644 --- a/lib/CodeGen/CGExprCXX.cpp +++ b/lib/CodeGen/CGExprCXX.cpp @@ -240,6 +240,8 @@ RValue CodeGenFunction::EmitCXXMemberCallExpr(const CXXMemberCallExpr *CE, 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 @@ RValue CodeGenFunction::EmitCXXMemberCallExpr(const CXXMemberCallExpr *CE, 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 5eede66cd7..a0b6e8c6bd 100644 --- a/test/CodeGenCXX/devirtualize-virtual-function-calls.cpp +++ b/test/CodeGenCXX/devirtualize-virtual-function-calls.cpp @@ -53,3 +53,21 @@ void f() { 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(); + } +}