Add CodeGenFunction::ReturnTypeUsesSret
 - Hook so NeXT runtime doesn't depend on ABI.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@56034 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CGCall.cpp b/lib/CodeGen/CGCall.cpp
index 8900432..8b7400a 100644
--- a/lib/CodeGen/CGCall.cpp
+++ b/lib/CodeGen/CGCall.cpp
@@ -117,6 +117,10 @@
 
 /***/
 
+bool CodeGenFunction::ReturnTypeUsesSret(QualType RetTy) {
+  return hasAggregateLLVMType(RetTy);
+}
+
 void CodeGenFunction::EmitFunctionProlog(llvm::Function *Fn,
                                          QualType RetTy, 
                                          const FunctionArgList &Args) {
diff --git a/lib/CodeGen/CGObjCMac.cpp b/lib/CodeGen/CGObjCMac.cpp
index a64b160..ff7717d 100644
--- a/lib/CodeGen/CGObjCMac.cpp
+++ b/lib/CodeGen/CGObjCMac.cpp
@@ -158,7 +158,8 @@
   ObjCTypesHelper(CodeGen::CodeGenModule &cgm);
   ~ObjCTypesHelper();
   
-  llvm::Value *getMessageSendFn(bool IsSuper, const llvm::Type *ReturnTy);
+  llvm::Value *getMessageSendFn(bool IsSuper, bool isStret, 
+                                const llvm::Type *ReturnTy);
 };
 
 class CGObjCMac : public CodeGen::CGObjCRuntime {
@@ -528,13 +529,11 @@
                                       CGF.getContext().getObjCSelType()));
   ActualArgs.insert(ActualArgs.end(), CallArgs.begin(), CallArgs.end());
 
-  // FIXME: This is a hack, we are implicitly coordinating with
-  // EmitCall, which will move the return type to the first parameter
-  // and set the structure return flag. See getMessageSendFn().
-                                                   
-  const llvm::Type *ReturnTy = CGM.getTypes().ConvertType(ResultType);
-  return CGF.EmitCall(ObjCTypes.getMessageSendFn(IsSuper, ReturnTy),
-                      ResultType, ActualArgs);
+  llvm::Value *Fn = 
+    ObjCTypes.getMessageSendFn(IsSuper, 
+                               CGF.ReturnTypeUsesSret(ResultType),
+                               CGM.getTypes().ConvertType(ResultType));
+  return CGF.EmitCall(Fn, ResultType, ActualArgs);
 }
 
 llvm::Value *CGObjCMac::GenerateProtocolRef(llvm::IRBuilder<> &Builder, 
@@ -2249,12 +2248,13 @@
 }
 
 llvm::Value *ObjCTypesHelper::getMessageSendFn(bool IsSuper, 
+                                               bool IsStret,
                                                const llvm::Type *ReturnTy) {
   llvm::Function *F;
   llvm::FunctionType *CallFTy;
   
   // FIXME: Should we be caching any of this?
-  if (!ReturnTy->isSingleValueType()) {
+  if (IsStret) {
     F = IsSuper ? MessageSendSuperStretFn : MessageSendStretFn;
     std::vector<const llvm::Type*> Params(3);
     Params[0] = llvm::PointerType::getUnqual(ReturnTy);
diff --git a/lib/CodeGen/CodeGenFunction.h b/lib/CodeGen/CodeGenFunction.h
index 5054b56..f5eba15 100644
--- a/lib/CodeGen/CodeGenFunction.h
+++ b/lib/CodeGen/CodeGenFunction.h
@@ -138,6 +138,10 @@
                      const FunctionArgList &Args);
   void FinishFunction(SourceLocation EndLoc=SourceLocation());
 
+  /// ReturnTypeUsesSret - Return true iff the given type uses 'sret'
+  /// when used as a return type.
+  bool ReturnTypeUsesSret(QualType RetTy);
+
   /// EmitFunctionProlog - Emit the target specific LLVM code to load
   /// the arguments for the given function. This is also responsible
   /// for naming the LLVM function arguments.