[cfe-commits] r51403 - /cfe/trunk/lib/CodeGen/CGStmt.cpp
Eli Friedman
eli.friedman at gmail.com
Wed May 21 18:22:33 PDT 2008
Author: efriedma
Date: Wed May 21 20:22:33 2008
New Revision: 51403
URL: http://llvm.org/viewvc/llvm-project?rev=51403&view=rev
Log:
Minor refactoring: compute the return value separately from emitting the
ret.
Modified:
cfe/trunk/lib/CodeGen/CGStmt.cpp
Modified: cfe/trunk/lib/CodeGen/CGStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGStmt.cpp?rev=51403&r1=51402&r2=51403&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGStmt.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGStmt.cpp Wed May 21 20:22:33 2008
@@ -360,18 +360,21 @@
// Emit the result value, even if unused, to evalute the side effects.
const Expr *RV = S.getRetValue();
+ llvm::Value* RetValue = 0;
if (FnRetTy->isVoidType()) {
- // If the function returns void, emit ret void.
- Builder.CreateRetVoid();
+ // Make sure not to return anything
+ if (RV) {
+ // Evaluate the expression for side effects
+ EmitAnyExpr(RV);
+ }
} else if (RV == 0) {
- // Handle "return;" in a function that returns a value.
const llvm::Type *RetTy = CurFn->getFunctionType()->getReturnType();
- if (RetTy == llvm::Type::VoidTy)
- Builder.CreateRetVoid(); // struct return etc.
- else
- Builder.CreateRet(llvm::UndefValue::get(RetTy));
+ if (RetTy != llvm::Type::VoidTy) {
+ // Handle "return;" in a function that returns a value.
+ RetValue = llvm::UndefValue::get(RetTy);
+ }
} else if (!hasAggregateLLVMType(RV->getType())) {
- Builder.CreateRet(EmitScalarExpr(RV));
+ RetValue = EmitScalarExpr(RV);
} else if (RV->getType()->isAnyComplexType()) {
llvm::Value *SRetPtr = CurFn->arg_begin();
EmitComplexExprIntoAddr(RV, SRetPtr, false);
@@ -379,6 +382,12 @@
llvm::Value *SRetPtr = CurFn->arg_begin();
EmitAggExpr(RV, SRetPtr, false);
}
+
+ if (RetValue) {
+ Builder.CreateRet(RetValue);
+ } else {
+ Builder.CreateRetVoid();
+ }
// Emit a block after the branch so that dead code after a return has some
// place to go.
More information about the cfe-commits
mailing list