diff options
Diffstat (limited to 'clang/lib/CodeGen/CodeGenFunction.cpp')
-rw-r--r-- | clang/lib/CodeGen/CodeGenFunction.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index 572f5babd0a..7d451e8f6d0 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -276,6 +276,14 @@ void CodeGenFunction::FinishFunction(SourceLocation EndLoc) { if (CGM.getCodeGenOpts().EmitDeclMetadata) EmitDeclMetadata(); + + for (SmallVectorImpl<std::pair<llvm::Instruction *, llvm::Value *> >::iterator + I = DeferredReplacements.begin(), + E = DeferredReplacements.end(); + I != E; ++I) { + I->first->replaceAllUsesWith(I->second); + I->first->eraseFromParent(); + } } /// ShouldInstrumentFunction - Return true if the current function should be @@ -592,6 +600,14 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, // Indirect aggregate return; emit returned value directly into sret slot. // This reduces code size, and affects correctness in C++. ReturnValue = CurFn->arg_begin(); + } else if (CurFnInfo->getReturnInfo().getKind() == ABIArgInfo::InAlloca && + !hasScalarEvaluationKind(CurFnInfo->getReturnType())) { + // Load the sret pointer from the argument struct and return into that. + unsigned Idx = CurFnInfo->getReturnInfo().getInAllocaFieldIndex(); + llvm::Function::arg_iterator EI = CurFn->arg_end(); + --EI; + llvm::Value *Addr = Builder.CreateStructGEP(EI, Idx); + ReturnValue = Builder.CreateLoad(Addr, "agg.result"); } else { ReturnValue = CreateIRTemp(RetTy, "retval"); |