OSDN Git Service

PR c++/11852
authormmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4>
Sun, 7 Sep 2003 23:48:33 +0000 (23:48 +0000)
committermmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4>
Sun, 7 Sep 2003 23:48:33 +0000 (23:48 +0000)
* varasm.c (initializer_constant_valid_p): Correct logic for
CONSTRUCTORs.

PR c++/11852
* g++.dg/init/struct1.C: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@71187 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/init/struct1.C [new file with mode: 0644]
gcc/varasm.c

index 3308345..edd91eb 100644 (file)
@@ -1,3 +1,9 @@
+2003-09-07  Mark Mitchell  <mark@codesourcery.com>
+
+       PR c++/11852
+       * varasm.c (initializer_constant_valid_p): Correct logic for
+       CONSTRUCTORs.
+
 2003-09-07  Roger Sayle  <roger@eyesopen.com>
 
        * expr.c (expand_operands): New function to expand an operand pair.
index 51a0194..a88421b 100644 (file)
@@ -1,5 +1,10 @@
 2003-09-07  Mark Mitchell  <mark@codesourcery.com>
 
+       PR c++/11852
+       * g++.dg/init/struct1.C: New test.
+
+2003-09-07  Mark Mitchell  <mark@codesourcery.com>
+
        PR c++/12181
        * g++.dg/expr/comma1.C: New test.
 
diff --git a/gcc/testsuite/g++.dg/init/struct1.C b/gcc/testsuite/g++.dg/init/struct1.C
new file mode 100644 (file)
index 0000000..4cabc99
--- /dev/null
@@ -0,0 +1,6 @@
+struct bug {
+  const char *name;
+  unsigned long type;
+};
+
+struct bug s = { 0, (unsigned long) &s | 1 };
index d327cb2..84fbf25 100644 (file)
@@ -3476,11 +3476,27 @@ initializer_constant_valid_p (tree value, tree endtype)
           || TREE_CODE (TREE_TYPE (value)) == RECORD_TYPE)
          && TREE_CONSTANT (value)
          && CONSTRUCTOR_ELTS (value))
-       return
-         initializer_constant_valid_p (TREE_VALUE (CONSTRUCTOR_ELTS (value)),
-                                       endtype);
+       {
+         tree elt;
+         bool absolute = true;
+
+         for (elt = CONSTRUCTOR_ELTS (value); elt; elt = TREE_CHAIN (elt))
+           {
+             tree reloc;
+             value = TREE_VALUE (elt);
+             reloc = initializer_constant_valid_p (value, TREE_TYPE (value));
+             if (!reloc)
+               return NULL_TREE;
+             if (reloc != null_pointer_node)
+               absolute = false;
+           }
+         /* For a non-absolute relocation, there is no single
+            variable that can be "the variable that determines the
+            relocation."  */
+         return absolute ? null_pointer_node : error_mark_node;
+       }
 
-      return TREE_STATIC (value) ? null_pointer_node : 0;
+      return TREE_STATIC (value) ? null_pointer_node : NULL_TREE;
 
     case INTEGER_CST:
     case VECTOR_CST: