[llvm-commits] CVS: llvm-gcc/gcc/llvm-expand.c

Chris Lattner lattner at cs.uiuc.edu
Mon Oct 4 17:19:31 PDT 2004



Changes in directory llvm-gcc/gcc:

llvm-expand.c updated: 1.50 -> 1.51
---
Log message:

External globals with ctors cannot be marked LLVM constant.  This fixes
PR450: http://llvm.cs.uiuc.edu/PR450 , testcase test/Regression/C++Frontend/2004-10-04-ExternalGlobalConstant.cpp.tr,
and the Prolangs-C++/city program.


---
Diffs of the changes:  (+13 -5)

Index: llvm-gcc/gcc/llvm-expand.c
diff -u llvm-gcc/gcc/llvm-expand.c:1.50 llvm-gcc/gcc/llvm-expand.c:1.51
--- llvm-gcc/gcc/llvm-expand.c:1.50	Fri Jul 16 21:30:05 2004
+++ llvm-gcc/gcc/llvm-expand.c	Mon Oct  4 19:19:18 2004
@@ -7099,11 +7099,19 @@
       } else if (*/DECL_WEAK(decl) || DECL_COMMON(decl) || DECL_VIRTUAL_P(decl))
       G->Linkage = L_Weak;
 
-    if (TREE_READONLY(decl) && !TREE_SIDE_EFFECTS(decl) &&
-        (DECL_EXTERNAL(decl) || 
-         (DECL_INITIAL(decl) != error_mark_node && /* no ctor? */
-          DECL_INITIAL(decl) && TREE_CONSTANT(DECL_INITIAL(decl)))))
-      G->isConstant = 1;
+    if (TREE_READONLY(decl) && !TREE_SIDE_EFFECTS(decl)) {
+      if (DECL_EXTERNAL(decl)) {
+        /* Mark external globals constant only if they are lacking ctors/dtors.
+         */
+        if (!TYPE_NEEDS_CONSTRUCTING(TREE_TYPE(decl)))
+          G->isConstant = 1;
+      } else {
+        /* Mark readonly globals with constant initializes constant. */
+        if (DECL_INITIAL(decl) != error_mark_node && /* uninitialized? */
+            DECL_INITIAL(decl) && TREE_CONSTANT(DECL_INITIAL(decl)))
+          G->isConstant = 1;
+      }
+    }
     
     /* Allociate the LLVM global with the tree global */
     SET_DECL_LLVM(decl, G2V(G));






More information about the llvm-commits mailing list