[cfe-commits] r39653 - /cfe/cfe/trunk/CodeGen/CGStmt.cpp

clattner at cs.uiuc.edu clattner at cs.uiuc.edu
Wed Jul 11 09:46:41 PDT 2007


Author: clattner
Date: Wed Jul 11 11:46:41 2007
New Revision: 39653

URL: http://llvm.org/viewvc/llvm-project?rev=39653&view=rev
Log:
Implement implicit conversions in return stmts.

Modified:
    cfe/cfe/trunk/CodeGen/CGStmt.cpp

Modified: cfe/cfe/trunk/CodeGen/CGStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/CodeGen/CGStmt.cpp?rev=39653&r1=39652&r2=39653&view=diff

==============================================================================
--- cfe/cfe/trunk/CodeGen/CGStmt.cpp (original)
+++ cfe/cfe/trunk/CodeGen/CGStmt.cpp Wed Jul 11 11:46:41 2007
@@ -249,7 +249,10 @@
   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,11 +262,16 @@
       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!
-    Builder.CreateRet(RetVal.getVal());
   } else {
-    assert(0 && "FIXME: aggregate return unimp");
+    // 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





More information about the cfe-commits mailing list