[cfe-commits] r65381 - in /cfe/trunk: lib/CodeGen/CGExprConstant.cpp test/CodeGen/const-init.c

Daniel Dunbar daniel at zuster.org
Tue Feb 24 10:41:58 PST 2009


Author: ddunbar
Date: Tue Feb 24 12:41:57 2009
New Revision: 65381

URL: http://llvm.org/viewvc/llvm-project?rev=65381&view=rev
Log:
Fix IRgen of constant expressions referring to external/static
variables.
 - PR3657.

Modified:
    cfe/trunk/lib/CodeGen/CGExprConstant.cpp
    cfe/trunk/test/CodeGen/const-init.c

Modified: cfe/trunk/lib/CodeGen/CGExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprConstant.cpp?rev=65381&r1=65380&r2=65381&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprConstant.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprConstant.cpp Tue Feb 24 12:41:57 2009
@@ -384,11 +384,14 @@
       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;

Modified: cfe/trunk/test/CodeGen/const-init.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/const-init.c?rev=65381&r1=65380&r2=65381&view=diff

==============================================================================
--- cfe/trunk/test/CodeGen/const-init.c (original)
+++ cfe/trunk/test/CodeGen/const-init.c Tue Feb 24 12:41:57 2009
@@ -79,4 +79,11 @@
 // 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





More information about the cfe-commits mailing list