[cfe-commits] r39546 - /cfe/cfe/trunk/CodeGen/CodeGenFunction.cpp

clattner at cs.uiuc.edu clattner at cs.uiuc.edu
Wed Jul 11 09:45:28 PDT 2007


Author: clattner
Date: Wed Jul 11 11:45:28 2007
New Revision: 39546

URL: http://llvm.org/viewvc/llvm-project?rev=39546&view=rev
Log:
Add support for functions that return non-void.

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

Modified: cfe/cfe/trunk/CodeGen/CodeGenFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/CodeGen/CodeGenFunction.cpp?rev=39546&r1=39545&r2=39546&view=diff

==============================================================================
--- cfe/cfe/trunk/CodeGen/CodeGenFunction.cpp (original)
+++ cfe/cfe/trunk/CodeGen/CodeGenFunction.cpp Wed Jul 11 11:45:28 2007
@@ -113,10 +113,10 @@
 
 
 void CodeGenFunction::GenerateCode(const FunctionDecl *FD) {
-  const llvm::Type *Ty = ConvertType(FD->getType(), FD->getLocation());
+  const llvm::FunctionType *Ty = 
+    cast<llvm::FunctionType>(ConvertType(FD->getType(), FD->getLocation()));
   
-  CurFn = new Function(cast<llvm::FunctionType>(Ty),
-                       Function::ExternalLinkage,
+  CurFn = new Function(Ty, Function::ExternalLinkage,
                        FD->getName(), &CGM.getModule());
   
   BasicBlock *EntryBB = new BasicBlock("entry", CurFn);
@@ -127,8 +127,13 @@
   
   EmitStmt(FD->getBody());
   
-  // Emit a simple return for now.
-  Builder.CreateRetVoid();
+  // Emit a return for code that falls off the end.
+  // FIXME: if this is C++ main, this should return 0.
+  if (Ty->getReturnType() == llvm::Type::VoidTy)
+    Builder.CreateRetVoid();
+  else
+    Builder.CreateRet(UndefValue::get(Ty->getReturnType()));
+      
   
   
   // Verify that the function is well formed.





More information about the cfe-commits mailing list