Add support for emitting calls to functions that return references (as lvalues only for now)

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72449 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp
index f6081c6..45e19f1 100644
--- a/lib/CodeGen/CGExpr.cpp
+++ b/lib/CodeGen/CGExpr.cpp
@@ -1161,8 +1161,17 @@
 }
 
 LValue CodeGenFunction::EmitCallExprLValue(const CallExpr *E) {
-  // Can only get l-value for call expression returning aggregate type
   RValue RV = EmitCallExpr(E);
+
+  if (RV.isScalar()) {
+    assert(E->getCallReturnType()->isReferenceType() &&
+           "Can't have a scalar return unless the return type is a "
+           "reference type!");
+    
+    return LValue::MakeAddr(RV.getScalarVal(), E->getType().getCVRQualifiers(), 
+                            getContext().getObjCGCAttrKind(E->getType()));
+  }
+  
   return LValue::MakeAddr(RV.getAggregateAddr(),
                           E->getType().getCVRQualifiers(),
                           getContext().getObjCGCAttrKind(E->getType()));