diff options
author | Daniel Dunbar <daniel@zuster.org> | 2008-09-09 21:00:17 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2008-09-09 21:00:17 +0000 |
commit | 5ca2084cf9b529563209429857f01fdae9dcdfa5 (patch) | |
tree | 7bef0cceae645c1fc7d1f8011e04d96776c53652 /lib/CodeGen/CGStmt.cpp | |
parent | 8592b1d9a0f0acfcc1adbbcbf860a6f4fd429674 (diff) |
Use a unified return block.
- For the time being this means our emitted code is somewhat worse,
especially for aggregates. This will be fixed.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@56013 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGStmt.cpp')
-rw-r--r-- | lib/CodeGen/CGStmt.cpp | 32 |
1 files changed, 12 insertions, 20 deletions
diff --git a/lib/CodeGen/CGStmt.cpp b/lib/CodeGen/CGStmt.cpp index 4001be49f8..bf3469e538 100644 --- a/lib/CodeGen/CGStmt.cpp +++ b/lib/CodeGen/CGStmt.cpp @@ -405,33 +405,25 @@ void CodeGenFunction::EmitForStmt(const ForStmt &S) { void CodeGenFunction::EmitReturnStmt(const ReturnStmt &S) { // Emit the result value, even if unused, to evalute the side effects. const Expr *RV = S.getRetValue(); - - llvm::Value* RetValue = 0; - if (FnRetTy->isVoidType()) { - // Make sure not to return anything - if (RV) { - // Evaluate the expression for side effects + + // FIXME: Clean this up by using an LValue for ReturnTemp, + // EmitStoreThroughLValue, and EmitAnyExpr. + if (!ReturnValue) { + // Make sure not to return anything, but evaluate the expression + // for side effects. + if (RV) EmitAnyExpr(RV); - } } else if (RV == 0) { - const llvm::Type *RetTy = CurFn->getFunctionType()->getReturnType(); - if (RetTy != llvm::Type::VoidTy) { - // Handle "return;" in a function that returns a value. - RetValue = llvm::UndefValue::get(RetTy); - } + // Do nothing (return value is left uninitialized) } else if (!hasAggregateLLVMType(RV->getType())) { - RetValue = EmitScalarExpr(RV); + Builder.CreateStore(EmitScalarExpr(RV), ReturnValue); } else if (RV->getType()->isAnyComplexType()) { - EmitComplexExprIntoAddr(RV, CurFn->arg_begin(), false); + EmitComplexExprIntoAddr(RV, ReturnValue, false); } else { - EmitAggExpr(RV, CurFn->arg_begin(), false); + EmitAggExpr(RV, ReturnValue, false); } - if (RetValue) { - Builder.CreateRet(RetValue); - } else { - Builder.CreateRetVoid(); - } + Builder.CreateBr(ReturnBlock); // Emit a block after the branch so that dead code after a return has some // place to go. |