From 0db661e67f613f49d047cdf53da29b9741234ad8 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Fri, 21 Dec 2012 01:21:33 +0000 Subject: Don't eagerly emit a global static merged with a local extern. When we are visiting the extern declaration of 'i' in static int i = 99; int foo() { extern int i; return i; } We should not try to handle it as if it was an function static. That is, we must consider the written storage class. Fixing this then exposes that the assert in EmitGlobalVarDeclLValue and the if leading to its call are not completely accurate. They were passing before because the second decl was marked as having external storage. I changed them to check the linkage, which I find easier to understand. Last but not least, there is something strange going on with cuda and opencl. My guess is that the linkage computation for these languages needs to be audited, but I didn't want to change that in this patch so I just updated the storage classes to keep the current behavior. Thanks to Reed Kotler for reporting this. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@170827 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGExpr.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'lib/CodeGen/CGExpr.cpp') diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp index daab163d27..0f88b3cd40 100644 --- a/lib/CodeGen/CGExpr.cpp +++ b/lib/CodeGen/CGExpr.cpp @@ -1583,8 +1583,7 @@ EmitBitCastOfLValueToProperType(CodeGenFunction &CGF, static LValue EmitGlobalVarDeclLValue(CodeGenFunction &CGF, const Expr *E, const VarDecl *VD) { - assert((VD->hasExternalStorage() || VD->isFileVarDecl()) && - "Var decl must have external storage or be a file var decl!"); + assert(VD->hasLinkage() && "Var decl must have linkage!"); llvm::Value *V = CGF.CGM.GetAddrOfGlobalVar(VD); llvm::Type *RealVarTy = CGF.getTypes().ConvertTypeForMem(VD->getType()); @@ -1658,7 +1657,7 @@ LValue CodeGenFunction::EmitDeclRefLValue(const DeclRefExpr *E) { if (const VarDecl *VD = dyn_cast(ND)) { // Check if this is a global variable. - if (VD->hasExternalStorage() || VD->isFileVarDecl()) + if (VD->hasLinkage()) return EmitGlobalVarDeclLValue(*this, E, VD); bool isBlockVariable = VD->hasAttr(); -- cgit v1.2.3