When generating the call arguments in a thunk to call the thunkee, do
not make copies non-POD arguments or arguments passed by reference:
just copy the pointers directly. This eliminates another source of the
dreaded memcpy-of-non-PODs. Fixes PR7188.
llvm-svn: 104327
diff --git a/clang/lib/CodeGen/CGVTables.cpp b/clang/lib/CodeGen/CGVTables.cpp
index 3c9b45b..b66b9f8 100644
--- a/clang/lib/CodeGen/CGVTables.cpp
+++ b/clang/lib/CodeGen/CGVTables.cpp
@@ -2642,9 +2642,15 @@
ParmVarDecl *Param = *I;
QualType ArgType = Param->getType();
- // FIXME: Declaring a DeclRefExpr on the stack is kinda icky.
- DeclRefExpr ArgExpr(Param, ArgType.getNonReferenceType(), SourceLocation());
- CallArgs.push_back(std::make_pair(EmitCallArg(&ArgExpr, ArgType), ArgType));
+ // Load the argument corresponding to this parameter.
+ RValue Arg;
+ if (ArgType->isReferenceType() ||
+ (hasAggregateLLVMType(ArgType) && !ArgType->isAnyComplexType()))
+ Arg = RValue::get(Builder.CreateLoad(LocalDeclMap[Param]));
+ else
+ Arg = RValue::get(EmitLoadOfScalar(LocalDeclMap[Param], false, ArgType));
+
+ CallArgs.push_back(std::make_pair(Arg, ArgType));
}
// Get our callee.