From d4ecca135a78c3b4245264c10c191452603eff2d Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Tue, 24 Feb 2009 18:41:57 +0000 Subject: Fix IRgen of constant expressions referring to external/static variables. - PR3657. llvm-svn: 65381 --- clang/lib/CodeGen/CGExprConstant.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'clang/lib/CodeGen') diff --git a/clang/lib/CodeGen/CGExprConstant.cpp b/clang/lib/CodeGen/CGExprConstant.cpp index fd174237c09..1141c0da8aa 100644 --- a/clang/lib/CodeGen/CGExprConstant.cpp +++ b/clang/lib/CodeGen/CGExprConstant.cpp @@ -384,11 +384,14 @@ public: if (const FunctionDecl *FD = dyn_cast(Decl)) return CGM.GetAddrOfFunction(FD); if (const VarDecl* VD = dyn_cast(Decl)) { - if (VD->isFileVarDecl()) - return CGM.GetAddrOfGlobalVar(VD); - else if (VD->isBlockVarDecl()) { - assert(CGF && "Can't access static local vars without CGF"); - return CGF->GetAddrOfStaticLocalVar(VD); + // We can never refer to a variable with local storage. + if (!VD->hasLocalStorage()) { + if (VD->isFileVarDecl() || VD->hasExternalStorage()) + return CGM.GetAddrOfGlobalVar(VD); + else if (VD->isBlockVarDecl()) { + assert(CGF && "Can't access static local vars without CGF"); + return CGF->GetAddrOfStaticLocalVar(VD); + } } } break; -- cgit v1.2.3