diff options
-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; +} |