]> granicus.if.org Git - clang/commitdiff
Fix IRgen of constant expressions referring to external/static
authorDaniel Dunbar <daniel@zuster.org>
Tue, 24 Feb 2009 18:41:57 +0000 (18:41 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Tue, 24 Feb 2009 18:41:57 +0000 (18:41 +0000)
variables.
 - PR3657.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65381 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGExprConstant.cpp
test/CodeGen/const-init.c

index fd174237c09c553853b18ad423a25b60f5d4b912..1141c0da8aa4521aca8c7cef80812b1dedef4d6e 100644 (file)
@@ -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;
index 0ca7c24f0bff9484e9ec2c140cba7e05420b61e7..65a59e869a76c31a124e2491222161932ad50387 100644 (file)
@@ -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