[cfe-commits] r72449 - in /cfe/trunk: lib/CodeGen/CGExpr.cpp test/CodeGenCXX/references.cpp
Anders Carlsson
andersca at mac.com
Tue May 26 18:45:48 PDT 2009
Author: andersca
Date: Tue May 26 20:45:47 2009
New Revision: 72449
URL: http://llvm.org/viewvc/llvm-project?rev=72449&view=rev
Log:
Add support for emitting calls to functions that return references (as lvalues only for now)
Modified:
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/test/CodeGenCXX/references.cpp
Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=72449&r1=72448&r2=72449&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Tue May 26 20:45:47 2009
@@ -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()));
Modified: cfe/trunk/test/CodeGenCXX/references.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/references.cpp?rev=72449&r1=72448&r2=72449&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/references.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/references.cpp Tue May 26 20:45:47 2009
@@ -24,13 +24,19 @@
void f(const _Complex int&);
void f(const C&);
-C structfunc();
+C aggregate_return();
+
+bool& bool_reference_return();
+int& int_reference_return();
+_Complex int& complex_int_reference_return();
void test_bool() {
bool a = true;
f(a);
f(true);
+
+ bool_reference_return() = true;
}
void test_scalar() {
@@ -44,6 +50,8 @@
__attribute((vector_size(16))) typedef int vec4;
f((vec4){1,2,3,4}[0]);
+
+ int_reference_return() = 10;
}
void test_complex() {
@@ -51,12 +59,14 @@
f(a);
f(10i);
+
+ complex_int_reference_return() = 10i;
}
void test_aggregate() {
C c;
f(c);
- f(structfunc());
+ f(aggregate_return());
}
More information about the cfe-commits
mailing list