re PR c/17322 (initializer folding broken)
authorRichard Henderson <rth@redhat.com>
Thu, 9 Sep 2004 17:36:42 +0000 (10:36 -0700)
committerRichard Henderson <rth@gcc.gnu.org>
Thu, 9 Sep 2004 17:36:42 +0000 (10:36 -0700)
        PR c/17322
        * c-typeck.c (valid_compound_expr_initializer): Use only
        initializer_constant_valid_p, and not TREE_CONSTANT.
        (digest_init): Likewise.
        (output_init_element): Likewise.

From-SVN: r87245

gcc/ChangeLog
gcc/c-typeck.c
gcc/testsuite/gcc.dg/pr17322.c [new file with mode: 0644]

index 43c658b00abf83bf76a5401a8c99588536875a6c..84a8c3462b113bea674a9be27f056cbac1f13a10 100644 (file)
@@ -1,3 +1,11 @@
+2004-09-09  Richard Henderson  <rth@redhat.com>
+
+       PR c/17322
+       * c-typeck.c (valid_compound_expr_initializer): Use only
+       initializer_constant_valid_p, and not TREE_CONSTANT.
+       (digest_init): Likewise.
+       (output_init_element): Likewise.
+
 2004-09-09  Giovanni Bajo  <giovannibajo@gcc.gnu.org>
 
        * ra-build.c (copy_insn_p, remember_move, defuse_overlap_p_1,
index 1bab69565bb5f3139c656e5bab7204f7476eddc5..4cfd7ce35b5dc19bc7626cb8229ad3075e9a3362 100644 (file)
@@ -3737,8 +3737,7 @@ valid_compound_expr_initializer (tree value, tree endtype)
       return valid_compound_expr_initializer (TREE_OPERAND (value, 1),
                                              endtype);
     }
-  else if (! TREE_CONSTANT (value)
-          && ! initializer_constant_valid_p (value, endtype))
+  else if (!initializer_constant_valid_p (value, endtype))
     return error_mark_node;
   else
     return value;
@@ -4166,16 +4165,8 @@ digest_init (tree type, tree init, bool strict_string, int require_constant)
            inside_init = error_mark_node;
        }
       else if (require_constant
-              && (!TREE_CONSTANT (inside_init)
-                  /* This test catches things like `7 / 0' which
-                     result in an expression for which TREE_CONSTANT
-                     is true, but which is not actually something
-                     that is a legal constant.  We really should not
-                     be using this function, because it is a part of
-                     the back-end.  Instead, the expression should
-                     already have been turned into ERROR_MARK_NODE.  */
-                  || !initializer_constant_valid_p (inside_init,
-                                                    TREE_TYPE (inside_init))))
+              && !initializer_constant_valid_p (inside_init,
+                                                TREE_TYPE (inside_init)))
        {
          error_init ("initializer element is not constant");
          inside_init = error_mark_node;
@@ -4203,7 +4194,8 @@ digest_init (tree type, tree init, bool strict_string, int require_constant)
          inside_init = error_mark_node;
        }
       else if (require_constant
-              && initializer_constant_valid_p (inside_init, TREE_TYPE (inside_init)) == 0)
+              && !initializer_constant_valid_p (inside_init,
+                                                TREE_TYPE (inside_init)))
        {
          error_init ("initializer element is not computable at load time");
          inside_init = error_mark_node;
@@ -5585,21 +5577,23 @@ output_init_element (tree value, bool strict_string, tree type, tree field,
     constructor_erroneous = 1;
   else if (!TREE_CONSTANT (value))
     constructor_constant = 0;
-  else if (initializer_constant_valid_p (value, TREE_TYPE (value)) == 0
+  else if (!initializer_constant_valid_p (value, TREE_TYPE (value))
           || ((TREE_CODE (constructor_type) == RECORD_TYPE
                || TREE_CODE (constructor_type) == UNION_TYPE)
               && DECL_C_BIT_FIELD (field)
               && TREE_CODE (value) != INTEGER_CST))
     constructor_simple = 0;
 
-  if (require_constant_value && ! TREE_CONSTANT (value))
+  if (!initializer_constant_valid_p (value, TREE_TYPE (value)))
     {
-      error_init ("initializer element is not constant");
-      value = error_mark_node;
+      if (require_constant_value)
+       {
+         error_init ("initializer element is not constant");
+         value = error_mark_node;
+       }
+      else if (require_constant_elements)
+       pedwarn ("initializer element is not computable at load time");
     }
-  else if (require_constant_elements
-          && initializer_constant_valid_p (value, TREE_TYPE (value)) == 0)
-    pedwarn ("initializer element is not computable at load time");
 
   /* If this field is empty (and not at the end of structure),
      don't do anything other than checking the initializer.  */
diff --git a/gcc/testsuite/gcc.dg/pr17322.c b/gcc/testsuite/gcc.dg/pr17322.c
new file mode 100644 (file)
index 0000000..7057872
--- /dev/null
@@ -0,0 +1,5 @@
+/* PR 17322 */
+
+struct s { int a; int b[1]; };
+struct s x;
+int *y = ((struct s *)&x.a)->b;