diff options
| author | Anders Carlsson <andersca@mac.com> | 2009-05-20 00:36:58 +0000 | 
|---|---|---|
| committer | Anders Carlsson <andersca@mac.com> | 2009-05-20 00:36:58 +0000 | 
| commit | 7d4c083c1909ba1da94754abfab157efcbe7e898 (patch) | |
| tree | 12e227ef70bb5fdd86df6ab61e68d2782a914fe9 | |
| parent | 7248923a5da4244e426b74205402df78b607ea54 (diff) | |
| download | bcm5719-llvm-7d4c083c1909ba1da94754abfab157efcbe7e898.tar.gz bcm5719-llvm-7d4c083c1909ba1da94754abfab157efcbe7e898.zip  | |
Bind references to lvalues correctly.
llvm-svn: 72150
| -rw-r--r-- | clang/lib/CodeGen/CGExpr.cpp | 6 | ||||
| -rw-r--r-- | clang/test/CodeGenCXX/references.cpp | 27 | 
2 files changed, 33 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index dc447983f0e..bb9f20003ac 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -72,6 +72,12 @@ RValue CodeGenFunction::EmitAnyExprToTemp(const Expr *E, llvm::Value *AggLoc,  RValue CodeGenFunction::EmitReferenceBindingToExpr(const Expr* E,                                                     QualType DestType) { +  if (E->isLvalue(getContext()) == Expr::LV_Valid) { +    // Emit the expr as an lvalue. +    LValue LV = EmitLValue(E); +    return RValue::get(LV.getAddress()); +  } +      CGM.ErrorUnsupported(E, "reference binding");    return GetUndefRValue(DestType);  } diff --git a/clang/test/CodeGenCXX/references.cpp b/clang/test/CodeGenCXX/references.cpp index 26d7157e1cb..2b2b1ff8969 100644 --- a/clang/test/CodeGenCXX/references.cpp +++ b/clang/test/CodeGenCXX/references.cpp @@ -14,3 +14,30 @@ int& gr = g;  void t3() {    int b = gr;  } + +// Test reference binding. + +struct C {}; + +void f(const int&); +void f(const _Complex int&); +void f(const C&); + +void test_scalar() { +  int a = 10; +   +  f(a); +} + +void test_complex() { +  _Complex int a = 10i; +   +  f(a); +} + +void test_aggregate() { +  C c; +   +  f(c); +} +  | 

