diff options
Diffstat (limited to 'clang')
-rw-r--r-- | clang/lib/CodeGen/CGExprConstant.cpp | 13 | ||||
-rw-r--r-- | clang/test/CodeGen/const-init.c | 7 |
2 files changed, 15 insertions, 5 deletions
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<FunctionDecl>(Decl)) return CGM.GetAddrOfFunction(FD); if (const VarDecl* VD = dyn_cast<VarDecl>(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; diff --git a/clang/test/CodeGen/const-init.c b/clang/test/CodeGen/const-init.c index 0ca7c24f0bf..65a59e869a7 100644 --- a/clang/test/CodeGen/const-init.c +++ b/clang/test/CodeGen/const-init.c @@ -79,4 +79,11 @@ long long g16 = (long long) ((void*) 0xFFFFFFFF); // RUN: grep '@g17 = global i32\* @g15' %t && int *g17 = (int *) ((long) &g15); +// RUN: grep '@g18.p = internal global \[1 x i32\*\] \[i32\* @g19\]' %t && +// FIXME: Should we really accept this in Sema? +void g18(void) { + extern int g19; + static int *p[] = { &g19 }; +} + // RUN: true |