summaryrefslogtreecommitdiffstats
path: root/clang/CodeGen/CodeGenFunction.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2007-06-02 03:02:07 +0000
committerChris Lattner <sabre@nondot.org>2007-06-02 03:02:07 +0000
commitadb6372aa58456513b3db54ed552aefb61b6d887 (patch)
tree86f8bf7df95d556da6b7eacdde92628dc556295a /clang/CodeGen/CodeGenFunction.cpp
parentdb91b167558b8eae05223e317607575807da03a7 (diff)
downloadbcm5719-llvm-adb6372aa58456513b3db54ed552aefb61b6d887.tar.gz
bcm5719-llvm-adb6372aa58456513b3db54ed552aefb61b6d887.zip
Add support for functions that return non-void.
llvm-svn: 39546
Diffstat (limited to 'clang/CodeGen/CodeGenFunction.cpp')
-rw-r--r--clang/CodeGen/CodeGenFunction.cpp15
1 files changed, 10 insertions, 5 deletions
diff --git a/clang/CodeGen/CodeGenFunction.cpp b/clang/CodeGen/CodeGenFunction.cpp
index 46ca193025a..6c7b714fb7f 100644
--- a/clang/CodeGen/CodeGenFunction.cpp
+++ b/clang/CodeGen/CodeGenFunction.cpp
@@ -113,10 +113,10 @@ const llvm::Type *CodeGenFunction::ConvertType(QualType T, SourceLocation Loc) {
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 @@ void CodeGenFunction::GenerateCode(const FunctionDecl *FD) {
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.
OpenPOWER on IntegriCloud