[cfe-commits] r40993 - in /cfe/trunk/CodeGen: CGExpr.cpp CodeGenFunction.cpp
Chris Lattner
sabre at nondot.org
Fri Aug 10 10:02:28 PDT 2007
Author: lattner
Date: Fri Aug 10 12:02:28 2007
New Revision: 40993
URL: http://llvm.org/viewvc/llvm-project?rev=40993&view=rev
Log:
implement initial codegen for aggregate return functions. This implements
codegen for:
_Complex double bar(int);
void test(_Complex double*);
void test2(int c) {
_Complex double X;
X = bar(1);
test(&X);
}
Modified:
cfe/trunk/CodeGen/CGExpr.cpp
cfe/trunk/CodeGen/CodeGenFunction.cpp
Modified: cfe/trunk/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CGExpr.cpp?rev=40993&r1=40992&r2=40993&view=diff
==============================================================================
--- cfe/trunk/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/CodeGen/CGExpr.cpp Fri Aug 10 12:02:28 2007
@@ -721,7 +721,14 @@
llvm::SmallVector<llvm::Value*, 16> Args;
- // FIXME: Handle struct return.
+ // Handle struct-return functions by passing a pointer to the location that
+ // we would like to return into.
+ if (hasAggregateLLVMType(E->getType())) {
+ // Create a temporary alloca to hold the result of the call. :(
+ Args.push_back(CreateTempAlloca(ConvertType(E->getType())));
+ // FIXME: set the stret attribute on the argument.
+ }
+
for (unsigned i = 0, e = E->getNumArgs(); i != e; ++i) {
QualType ArgTy = E->getArg(i)->getType();
RValue ArgVal = EmitExpr(E->getArg(i));
@@ -752,8 +759,10 @@
llvm::Value *V = Builder.CreateCall(Callee, &Args[0], &Args[0]+Args.size());
if (V->getType() != llvm::Type::VoidTy)
V->setName("call");
-
- // FIXME: Struct return;
+ else if (hasAggregateLLVMType(E->getType()))
+ // Struct return.
+ return RValue::getAggregate(Args[0]);
+
return RValue::get(V);
}
Modified: cfe/trunk/CodeGen/CodeGenFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CodeGenFunction.cpp?rev=40993&r1=40992&r2=40993&view=diff
==============================================================================
--- cfe/trunk/CodeGen/CodeGenFunction.cpp (original)
+++ cfe/trunk/CodeGen/CodeGenFunction.cpp Fri Aug 10 12:02:28 2007
@@ -45,7 +45,7 @@
bool CodeGenFunction::hasAggregateLLVMType(QualType T) {
return !T->isRealType() && !T->isPointerType() && !T->isVoidType() &&
- !T->isVectorType();
+ !T->isVectorType() && !T->isFunctionType();
}
More information about the cfe-commits
mailing list