[llvm-bugs] [Bug 27621] New: [MS] Devirtualizing a method call on the result of a static_cast uses wrong this adjustment

via llvm-bugs llvm-bugs at lists.llvm.org
Tue May 3 11:38:17 PDT 2016


https://llvm.org/bugs/show_bug.cgi?id=27621

            Bug ID: 27621
           Summary: [MS] Devirtualizing a method call on the result of a
                    static_cast uses wrong this adjustment
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: normal
          Priority: P
         Component: LLVM Codegen
          Assignee: unassignedclangbugs at nondot.org
          Reporter: rnk at google.com
                CC: llvm-bugs at lists.llvm.org
            Blocks: 12477
    Classification: Unclassified

Consider:

struct A { virtual void f(); };
struct B { virtual void g(); };
struct C final : A, B {
  virtual void h();
  void g() override;
};
void doit(C *p) {
  // Fails to adjust from C* to B* when calling C::g
  static_cast<B*>(p)->g();
}

The problem is that we pass the wrong CXXMethodDecl to
adjustThisArgumentForVirtualFunctionCall. We pass B::g instead of C::g. B::g
has no 'this' adjustment in its prologue.

The fix is trivial:
diff --git a/lib/CodeGen/CGExprCXX.cpp b/lib/CodeGen/CGExprCXX.cpp
index a90610f..c6f46c3 100644
--- a/lib/CodeGen/CGExprCXX.cpp
+++ b/lib/CodeGen/CGExprCXX.cpp
@@ -274,7 +274,7 @@ RValue
CodeGenFunction::EmitCXXMemberOrOperatorMemberCallExpr(

   if (MD->isVirtual()) {
     This = CGM.getCXXABI().adjustThisArgumentForVirtualFunctionCall(
-        *this, MD, This, UseVirtualCall);
+        *this, CalleeDecl, This, UseVirtualCall);
   }

   return EmitCXXMemberOrOperatorCall(MD, Callee, ReturnValue,
This.getPointer(),

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20160503/e2d41b04/attachment.html>


More information about the llvm-bugs mailing list