diff options
author | Eli Friedman <eli.friedman@gmail.com> | 2009-05-27 05:39:06 +0000 |
---|---|---|
committer | Eli Friedman <eli.friedman@gmail.com> | 2009-05-27 05:39:06 +0000 |
commit | 4a18784dea763be146df68546e6dbf4233c33077 (patch) | |
tree | 71637c69aac7db542e72b71a4a40b103eb233101 | |
parent | 815215daf8f642b53a28212313fca7b9f77e5b9d (diff) |
Add IRGen support for local variables of reference type.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72462 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/CodeGen/CGDecl.cpp | 10 | ||||
-rw-r--r-- | test/CodeGenCXX/references.cpp | 6 |
2 files changed, 10 insertions, 6 deletions
diff --git a/lib/CodeGen/CGDecl.cpp b/lib/CodeGen/CGDecl.cpp index 52bb90e7f8..bcad77be51 100644 --- a/lib/CodeGen/CGDecl.cpp +++ b/lib/CodeGen/CGDecl.cpp @@ -332,11 +332,6 @@ void CodeGenFunction::EmitLocalBlockVarDecl(const VarDecl &D) { DI->EmitDeclareOfAutoVariable(&D, DeclPtr, Builder); } - if (D.getType()->isReferenceType()) { - CGM.ErrorUnsupported(&D, "declaration with reference type"); - return; - } - // If this local has an initializer, emit it now. if (const Expr *Init = D.getInit()) { llvm::Value *Loc = DeclPtr; @@ -344,7 +339,10 @@ void CodeGenFunction::EmitLocalBlockVarDecl(const VarDecl &D) { bool needsCopyDispose = BlockRequiresCopying(Ty); Loc = Builder.CreateStructGEP(DeclPtr, needsCopyDispose*2+4, "x"); } - if (!hasAggregateLLVMType(Init->getType())) { + if (Ty->isReferenceType()) { + llvm::Value *V = EmitReferenceBindingToExpr(Init, Ty).getScalarVal(); + EmitStoreOfScalar(V, Loc, false, Ty); + } else if (!hasAggregateLLVMType(Init->getType())) { llvm::Value *V = EmitScalarExpr(Init); EmitStoreOfScalar(V, Loc, D.getType().isVolatileQualified(), D.getType()); diff --git a/test/CodeGenCXX/references.cpp b/test/CodeGenCXX/references.cpp index 5c5518b38b..5d4ac06c5b 100644 --- a/test/CodeGenCXX/references.cpp +++ b/test/CodeGenCXX/references.cpp @@ -78,3 +78,9 @@ void test_aggregate() { int& reference_return() { return g; } + +int reference_decl() { + int& a = g; + const int& b = 1; + return a+b; +} |