Hook up global function and variable handling. We can now compile:
int X, bar(int,int,int);
short Y;
double foo() {
return bar(X, Y, 3);
}
into:
@X = external global i32 ; <i32*> [#uses=1]
@Y = external global i16 ; <i16*> [#uses=1]
define double @foo() {
entry:
%tmp = load i32* @X ; <i32> [#uses=1]
%tmp1 = load i16* @Y ; <i16> [#uses=1]
%promote = sext i16 %tmp1 to i32 ; <i32> [#uses=1]
%call = tail call i32 @bar( i32 %tmp, i32 %promote, i32 3 ) ; <i32> [#uses=1]
%conv = sitofp i32 %call to double ; <double> [#uses=1]
ret double %conv
}
declare i32 @bar(i32, i32, i32)
llvm-svn: 39663
diff --git a/clang/CodeGen/CodeGenFunction.cpp b/clang/CodeGen/CodeGenFunction.cpp
index d3abbc9..3c4a68b 100644
--- a/clang/CodeGen/CodeGenFunction.cpp
+++ b/clang/CodeGen/CodeGenFunction.cpp
@@ -47,14 +47,11 @@
LLVMIntTy = ConvertType(getContext().IntTy, FD->getLocation());
LLVMPointerWidth = Target.getPointerWidth(FD->getLocation());
- const llvm::FunctionType *Ty =
- cast<llvm::FunctionType>(ConvertType(FD->getType(), FD->getLocation()));
-
- // FIXME: param attributes for sext/zext etc.
-
+ CurFn = cast<llvm::Function>(CGM.GetAddrOfGlobalDecl(FD));
CurFuncDecl = FD;
- CurFn = new llvm::Function(Ty, llvm::Function::ExternalLinkage,
- FD->getName(), &CGM.getModule());
+
+ // TODO: Set up linkage and many other things.
+ assert(CurFn->isDeclaration() && "Function already has body?");
llvm::BasicBlock *EntryBB = new llvm::BasicBlock("entry", CurFn);
@@ -77,10 +74,10 @@
// 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)
+ if (CurFn->getReturnType() == llvm::Type::VoidTy)
Builder.CreateRetVoid();
else
- Builder.CreateRet(llvm::UndefValue::get(Ty->getReturnType()));
+ Builder.CreateRet(llvm::UndefValue::get(CurFn->getReturnType()));
// Verify that the function is well formed.
assert(!verifyFunction(*CurFn));