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: unassignedclangb...@nondot.org Reporter: r...@google.com CC: llvm-bugs@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.
_______________________________________________ llvm-bugs mailing list llvm-bugs@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs