Implement implicit conversions in return stmts.

llvm-svn: 39653
This commit is contained in:
Chris Lattner 2007-06-13 20:50:31 +00:00
parent 53621a535d
commit cf98efa73b

View File

@ -249,7 +249,10 @@ void CodeGenFunction::EmitReturnStmt(const ReturnStmt &S) {
if (RV)
RetVal = EmitExpr(RV);
if (CurFuncDecl->getType()->isVoidType()) {
QualType FnRetTy = CurFuncDecl->getType().getCanonicalType();
FnRetTy = cast<FunctionType>(FnRetTy)->getResultType();
if (FnRetTy->isVoidType()) {
// If the function returns void, emit ret void, and ignore the retval.
Builder.CreateRetVoid();
} else if (RV == 0) {
@ -259,12 +262,17 @@ void CodeGenFunction::EmitReturnStmt(const ReturnStmt &S) {
Builder.CreateRetVoid(); // struct return etc.
else
Builder.CreateRet(llvm::UndefValue::get(RetTy));
} else if (RetVal.isScalar()) {
// FIXME: return should coerce its operand to the return type!
} else {
// Do implicit conversions to the returned type.
RetVal = EmitConversion(RetVal, RV->getType(), FnRetTy, SourceLocation());
if (RetVal.isScalar()) {
// FIXME: Pass return loc in!
Builder.CreateRet(RetVal.getVal());
} else {
assert(0 && "FIXME: aggregate return unimp");
}
}
// Emit a block after the branch so that dead code after a return has some
// place to go.