From e5a321b5e8777c63d5ebfb896137dcf16ead4f15 Mon Sep 17 00:00:00 2001 From: Reid Kleckner Date: Wed, 7 Sep 2016 18:21:30 +0000 Subject: [MS] Fix prologue this adjustment when 'this' is passed indirectly Move the logic for doing this from the ABI argument lowering into EmitParmDecl, which runs for all parameters. Our codegen is slightly suboptimal in this case, as we may leave behind a dead store after optimization, but it's 32-bit inalloca, and this fixes the bug in a robust way. Fixes PR30293 llvm-svn: 280836 --- clang/lib/CodeGen/CGDecl.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'clang/lib/CodeGen/CGDecl.cpp') diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp index 037b1351c0f..5b4017cad37 100644 --- a/clang/lib/CodeGen/CGDecl.cpp +++ b/clang/lib/CodeGen/CGDecl.cpp @@ -13,6 +13,7 @@ #include "CodeGenFunction.h" #include "CGBlocks.h" +#include "CGCXXABI.h" #include "CGCleanup.h" #include "CGDebugInfo.h" #include "CGOpenCLRuntime.h" @@ -1769,6 +1770,24 @@ void CodeGenFunction::EmitParmDecl(const VarDecl &D, ParamValue Arg, setBlockContextParameter(IPD, ArgNo, Arg.getDirectValue()); return; } + + // Apply any prologue 'this' adjustments required by the ABI. Be careful to + // handle the case where 'this' is passed indirectly as part of an inalloca + // struct. + if (const CXXMethodDecl *MD = + dyn_cast_or_null(CurCodeDecl)) { + if (MD->isVirtual() && IPD == CXXABIThisDecl) { + llvm::Value *This = Arg.isIndirect() + ? Builder.CreateLoad(Arg.getIndirectAddress()) + : Arg.getDirectValue(); + This = CGM.getCXXABI().adjustThisParameterInVirtualFunctionPrologue( + *this, CurGD, This); + if (Arg.isIndirect()) + Builder.CreateStore(This, Arg.getIndirectAddress()); + else + Arg = ParamValue::forDirect(This); + } + } } Address DeclPtr = Address::invalid(); -- cgit v1.2.3