summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen/CodeGenFunction.cpp
diff options
context:
space:
mode:
authorEli Friedman <eli.friedman@gmail.com>2009-12-04 02:43:40 +0000
committerEli Friedman <eli.friedman@gmail.com>2009-12-04 02:43:40 +0000
commit4b1942cb8b63f525979b7c849169224276ea7df1 (patch)
treed1c6b5fb24399fbe941963c5b471c780f0e96444 /clang/lib/CodeGen/CodeGenFunction.cpp
parent495634e5ac146410bf9fef6df59e521cedbfd3bb (diff)
downloadbcm5719-llvm-4b1942cb8b63f525979b7c849169224276ea7df1.tar.gz
bcm5719-llvm-4b1942cb8b63f525979b7c849169224276ea7df1.zip
Make functions returning a struct indirectly evaluate the returned struct
directly into the sret pointer. This is an optimization in C, but is required for correctness in C++ for classes with a non-trivial copy constructor. llvm-svn: 90526
Diffstat (limited to 'clang/lib/CodeGen/CodeGenFunction.cpp')
-rw-r--r--clang/lib/CodeGen/CodeGenFunction.cpp16
1 files changed, 13 insertions, 3 deletions
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp
index 1e952f9a7db..88f02a9738c 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -179,9 +179,6 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy,
AllocaInsertPt->setName("allocapt");
ReturnBlock = createBasicBlock("return");
- ReturnValue = 0;
- if (!RetTy->isVoidType())
- ReturnValue = CreateTempAlloca(ConvertType(RetTy), "retval");
Builder.SetInsertPoint(EntryBB);
@@ -204,6 +201,19 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy,
// FIXME: Leaked.
CurFnInfo = &CGM.getTypes().getFunctionInfo(FnRetTy, Args);
+
+ if (RetTy->isVoidType()) {
+ // Void type; nothing to return.
+ ReturnValue = 0;
+ } else if (CurFnInfo->getReturnInfo().getKind() == ABIArgInfo::Indirect &&
+ hasAggregateLLVMType(CurFnInfo->getReturnType())) {
+ // Indirect aggregate return; emit returned value directly into sret slot.
+ // This reduces code size, and is also affects correctness in C++.
+ ReturnValue = CurFn->arg_begin();
+ } else {
+ ReturnValue = CreateTempAlloca(ConvertType(RetTy), "retval");
+ }
+
EmitFunctionProlog(*CurFnInfo, CurFn, Args);
// If any of the arguments have a variably modified type, make sure to
OpenPOWER on IntegriCloud