summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2009-05-27 01:45:47 +0000
committerAnders Carlsson <andersca@mac.com>2009-05-27 01:45:47 +0000
commit4ae70ff9a34727fd6d749d01f569efd22a7176f8 (patch)
tree631f121d030678957411f7250474d164c7027fb5 /clang
parent3e97f3b35db533ef81ea347630b0f9fdbd9384e8 (diff)
downloadbcm5719-llvm-4ae70ff9a34727fd6d749d01f569efd22a7176f8.tar.gz
bcm5719-llvm-4ae70ff9a34727fd6d749d01f569efd22a7176f8.zip
Add support for emitting calls to functions that return references (as lvalues only for now)
llvm-svn: 72449
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/CodeGen/CGExpr.cpp11
-rw-r--r--clang/test/CodeGenCXX/references.cpp14
2 files changed, 22 insertions, 3 deletions
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index f6081c61f9c..45e19f139ac 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -1161,8 +1161,17 @@ LValue CodeGenFunction::EmitBinaryOperatorLValue(const BinaryOperator *E) {
}
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()));
diff --git a/clang/test/CodeGenCXX/references.cpp b/clang/test/CodeGenCXX/references.cpp
index 0124f695b3b..97fc15e0359 100644
--- a/clang/test/CodeGenCXX/references.cpp
+++ b/clang/test/CodeGenCXX/references.cpp
@@ -24,13 +24,19 @@ void f(const int&);
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 @@ void test_scalar() {
__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 @@ void test_complex() {
f(a);
f(10i);
+
+ complex_int_reference_return() = 10i;
}
void test_aggregate() {
C c;
f(c);
- f(structfunc());
+ f(aggregate_return());
}
OpenPOWER on IntegriCloud