From e9f2f45fe9bf79bd4aea47fa1ad9204b68510fd9 Mon Sep 17 00:00:00 2001 From: Anders Carlsson Date: Wed, 27 May 2009 03:37:57 +0000 Subject: [PATCH] Functions that return references can be rvalues as well. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72457 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGExprComplex.cpp | 3 +++ lib/CodeGen/CGExprScalar.cpp | 3 +++ test/CodeGenCXX/references.cpp | 3 +++ 3 files changed, 9 insertions(+) diff --git a/lib/CodeGen/CGExprComplex.cpp b/lib/CodeGen/CGExprComplex.cpp index 3e28490f6f..618e446bf1 100644 --- a/lib/CodeGen/CGExprComplex.cpp +++ b/lib/CodeGen/CGExprComplex.cpp @@ -255,6 +255,9 @@ VisitImaginaryLiteral(const ImaginaryLiteral *IL) { ComplexPairTy ComplexExprEmitter::VisitCallExpr(const CallExpr *E) { + if (E->getCallReturnType()->isReferenceType()) + return EmitLoadOfLValue(E); + return CGF.EmitCallExpr(E).getComplexVal(); } diff --git a/lib/CodeGen/CGExprScalar.cpp b/lib/CodeGen/CGExprScalar.cpp index 8cd84ecdb4..e14d40c3b6 100644 --- a/lib/CodeGen/CGExprScalar.cpp +++ b/lib/CodeGen/CGExprScalar.cpp @@ -223,6 +223,9 @@ public: Value *EmitCastExpr(const Expr *E, QualType T); Value *VisitCallExpr(const CallExpr *E) { + if (E->getCallReturnType()->isReferenceType()) + return EmitLoadOfLValue(E); + return CGF.EmitCallExpr(E).getScalarVal(); } diff --git a/test/CodeGenCXX/references.cpp b/test/CodeGenCXX/references.cpp index aee395251e..e5db446fae 100644 --- a/test/CodeGenCXX/references.cpp +++ b/test/CodeGenCXX/references.cpp @@ -38,6 +38,7 @@ void test_bool() { f(true); bool_reference_return() = true; + a = bool_reference_return(); } void test_scalar() { @@ -53,6 +54,7 @@ void test_scalar() { f((vec4){1,2,3,4}[0]); int_reference_return() = 10; + a = int_reference_return(); } void test_complex() { @@ -62,6 +64,7 @@ void test_complex() { f(10i); complex_int_reference_return() = 10i; + a = complex_int_reference_return(); } void test_aggregate() { -- 2.40.0