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);
}

llvm-svn: 40993
This commit is contained in:
Chris Lattner 2007-08-10 17:02:28 +00:00
parent 02697701d9
commit 90d9120453
2 changed files with 13 additions and 4 deletions

View File

@ -721,7 +721,14 @@ RValue CodeGenFunction::EmitCallExpr(const CallExpr *E) {
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 @@ RValue CodeGenFunction::EmitCallExpr(const CallExpr *E) {
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);
}

View File

@ -45,7 +45,7 @@ const llvm::Type *CodeGenFunction::ConvertType(QualType T) {
bool CodeGenFunction::hasAggregateLLVMType(QualType T) {
return !T->isRealType() && !T->isPointerType() && !T->isVoidType() &&
!T->isVectorType();
!T->isVectorType() && !T->isFunctionType();
}