[cfe-commits] r72462 - in /cfe/trunk: lib/CodeGen/CGDecl.cpp test/CodeGenCXX/references.cpp
Eli Friedman
eli.friedman at gmail.com
Tue May 26 22:39:07 PDT 2009
Author: efriedma
Date: Wed May 27 00:39:06 2009
New Revision: 72462
URL: http://llvm.org/viewvc/llvm-project?rev=72462&view=rev
Log:
Add IRGen support for local variables of reference type.
Modified:
cfe/trunk/lib/CodeGen/CGDecl.cpp
cfe/trunk/test/CodeGenCXX/references.cpp
Modified: cfe/trunk/lib/CodeGen/CGDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDecl.cpp?rev=72462&r1=72461&r2=72462&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDecl.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDecl.cpp Wed May 27 00:39:06 2009
@@ -332,11 +332,6 @@
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 @@
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());
Modified: cfe/trunk/test/CodeGenCXX/references.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/references.cpp?rev=72462&r1=72461&r2=72462&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/references.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/references.cpp Wed May 27 00:39:06 2009
@@ -78,3 +78,9 @@
int& reference_return() {
return g;
}
+
+int reference_decl() {
+ int& a = g;
+ const int& b = 1;
+ return a+b;
+}
More information about the cfe-commits
mailing list