aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/CGExpr.cpp
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2012-12-21 01:21:33 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2012-12-21 01:21:33 +0000
commit0db661e67f613f49d047cdf53da29b9741234ad8 (patch)
treed369c42c043e0b10367ad0bd30770b031f907692 /lib/CodeGen/CGExpr.cpp
parente34e1939ad67576293b2b205b2169488cc6b3b14 (diff)
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
Diffstat (limited to 'lib/CodeGen/CGExpr.cpp')
-rw-r--r--lib/CodeGen/CGExpr.cpp5
1 files changed, 2 insertions, 3 deletions
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<VarDecl>(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<BlocksAttr>();