[cfe-commits] r72133 - in /cfe/trunk: lib/CodeGen/CGExpr.cpp test/CodeGenCXX/references.cpp
Anders Carlsson
andersca at mac.com
Tue May 19 13:40:02 PDT 2009
Author: andersca
Date: Tue May 19 15:40:02 2009
New Revision: 72133
URL: http://llvm.org/viewvc/llvm-project?rev=72133&view=rev
Log:
Improve support for irgen of references.
Added:
cfe/trunk/test/CodeGenCXX/references.cpp
Modified:
cfe/trunk/lib/CodeGen/CGExpr.cpp
Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=72133&r1=72132&r2=72133&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Tue May 19 15:40:02 2009
@@ -634,8 +634,10 @@
LValue LV;
bool GCable = VD->hasLocalStorage() && !VD->hasAttr<BlocksAttr>();
if (VD->hasExternalStorage()) {
- LV = LValue::MakeAddr(CGM.GetAddrOfGlobalVar(VD),
- E->getType().getCVRQualifiers(),
+ llvm::Value *V = CGM.GetAddrOfGlobalVar(VD);
+ if (VD->getType()->isReferenceType())
+ V = Builder.CreateLoad(V, "tmp");
+ LV = LValue::MakeAddr(V, E->getType().getCVRQualifiers(),
getContext().getObjCGCAttrKind(E->getType()));
}
else {
@@ -657,13 +659,17 @@
V = Builder.CreateBitCast(V, PtrStructTy);
V = Builder.CreateStructGEP(V, needsCopyDispose*2 + 4, "x");
}
+ if (VD->getType()->isReferenceType())
+ V = Builder.CreateLoad(V, "tmp");
LV = LValue::MakeAddr(V, E->getType().getCVRQualifiers(), attr);
}
LValue::SetObjCNonGC(LV, GCable);
return LV;
} else if (VD && VD->isFileVarDecl()) {
- LValue LV = LValue::MakeAddr(CGM.GetAddrOfGlobalVar(VD),
- E->getType().getCVRQualifiers(),
+ llvm::Value *V = CGM.GetAddrOfGlobalVar(VD);
+ if (VD->getType()->isReferenceType())
+ V = Builder.CreateLoad(V, "tmp");
+ LValue LV = LValue::MakeAddr(V, E->getType().getCVRQualifiers(),
getContext().getObjCGCAttrKind(E->getType()));
if (LV.isObjCStrong())
LV.SetGlobalObjCRef(LV, true);
Added: cfe/trunk/test/CodeGenCXX/references.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/references.cpp?rev=72133&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/references.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/references.cpp Tue May 19 15:40:02 2009
@@ -0,0 +1,16 @@
+// RUN: clang-cc -verify -emit-llvm -o %t %s
+
+void t1() {
+ extern int& a;
+ int b = a;
+}
+
+void t2(int& a) {
+ int b = a;
+}
+
+int g;
+int& gr = g;
+void t3() {
+ int b = gr;
+}
More information about the cfe-commits
mailing list