For this fix I've assumed that it is now the job of the various places that
do calculations with sizetypes to flag overflows where this is desired.

bootstrapped/regtested on i686-pc-linux-gnu .
2013-07-04  Joern Rennecke <joern.renne...@embecosm.com>
gcc:
        PR c/57821
        * c/c-typeck.c (set_init_index): When folding, check for index overflow.
        * c-family/c-common.c (complete_array_type): Delay folding first index
        like other indices.  When folding, check for index overflow.
gcc/testsuite:
        PR c/57821
        * gcc.dg/large-size-array-6.c: New test.

Index: c/c-typeck.c
===================================================================
--- c/c-typeck.c        (revision 200606)
+++ c/c-typeck.c        (working copy)
@@ -7217,6 +7217,8 @@ set_init_index (tree first, tree last,
       if (last)
        constant_expression_warning (last);
       constructor_index = convert (bitsizetype, first);
+      if (tree_int_cst_lt (constructor_index, first))
+       TREE_OVERFLOW (constructor_index) = 1;
 
       if (last)
        {
Index: c-family/c-common.c
===================================================================
--- c-family/c-common.c (revision 200606)
+++ c-family/c-common.c (working copy)
@@ -9809,8 +9809,8 @@ complete_array_type (tree *ptype, tree i
              bool fold_p = false;
 
              if ((*v)[0].index)
-               maxindex = fold_convert_loc (input_location, sizetype,
-                                            (*v)[0].index);
+               maxindex = (*v)[0].index, fold_p = true;
+
              curindex = maxindex;
 
              for (cnt = 1; vec_safe_iterate (v, cnt, &ce); cnt++)
@@ -9821,15 +9821,28 @@ complete_array_type (tree *ptype, tree i
                  else
                    {
                      if (fold_p)
-                       curindex = fold_convert (sizetype, curindex);
+                       {
+                         /* Since we treat size types now as ordinary
+                            unsigned types, we need an explicit overflow
+                            check.  */
+                         tree orig = curindex;
+                         curindex = fold_convert (sizetype, curindex);
+                         if (tree_int_cst_lt (curindex, orig))
+                           TREE_OVERFLOW (curindex) = 1;
+                       }
                      curindex = size_binop (PLUS_EXPR, curindex,
                                             size_one_node);
                    }
                  if (tree_int_cst_lt (maxindex, curindex))
                    maxindex = curindex, fold_p = curfold_p;
                }
-              if (fold_p)
-                maxindex = fold_convert (sizetype, maxindex);
+             if (fold_p)
+               {
+                 tree orig = maxindex;
+                 maxindex = fold_convert (sizetype, maxindex);
+                 if (tree_int_cst_lt (maxindex, orig))
+                   TREE_OVERFLOW (maxindex) = 1;
+               }
            }
        }
       else
Index: testsuite/gcc.dg/large-size-array-6.c
===================================================================
--- testsuite/gcc.dg/large-size-array-6.c       (revision 0)
+++ testsuite/gcc.dg/large-size-array-6.c       (working copy)
@@ -0,0 +1,6 @@
+/* PR c/57821 */
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+static char * name[] = {
+    [0x8000000000000000]  = "bar"
+  }; /* { dg-error "too large" } */

Reply via email to