re PR c/25309 (ICE on initialization of a huge array)
authorJoseph Myers <joseph@codesourcery.com>
Wed, 26 Sep 2007 12:32:27 +0000 (13:32 +0100)
committerJoseph Myers <jsm28@gcc.gnu.org>
Wed, 26 Sep 2007 12:32:27 +0000 (13:32 +0100)
PR c/25309
* c-common.c (complete_array_type): Diagnose too-large arrays and
set type to error_mark_node.

testsuite:
* gcc.dg/large-size-array-2.c: Expect diagnostic for too-large
array.
* gcc.dg/large-size-array-4.c: New.  Copy of large-size-array-2.c
without -O2.

From-SVN: r128811

gcc/ChangeLog
gcc/c-common.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/large-size-array-2.c
gcc/testsuite/gcc.dg/large-size-array-4.c [new file with mode: 0644]

index f5fb4a62c082509e4925519b7d830ffa592a0acb..a126c955f5b90e16710f3dcdc05cacd9556778b8 100644 (file)
@@ -1,3 +1,9 @@
+2007-09-26  Joseph Myers  <joseph@codesourcery.com>
+
+       PR c/25309
+       * c-common.c (complete_array_type): Diagnose too-large arrays and
+       set type to error_mark_node.
+
 2007-09-26  Richard Guenther  <rguenther@suse.de>
 
        PR tree-optimization/30375
index 8ebc92007cacdc84ec41cfffdf43fc637831c23e..bdb8d8009ed5aa7aa2d761bfd21c04627e806704 100644 (file)
@@ -7049,6 +7049,16 @@ complete_array_type (tree *ptype, tree initial_value, bool do_default)
   else
     type = c_build_qualified_type (main_type, quals);
 
+  if (COMPLETE_TYPE_P (type)
+      && TREE_CODE (TYPE_SIZE_UNIT (type)) == INTEGER_CST
+      && TREE_OVERFLOW (TYPE_SIZE_UNIT (type)))
+    {
+      error ("size of array is too large");
+      /* If we proceed with the array type as it is, we'll eventually
+        crash in tree_low_cst().  */
+      type = error_mark_node;
+    }
+
   *ptype = type;
   return failure;
 }
index c43dad2773fee812cbf9db2f2d6170009b648686..d2bb72533d9ba5d20d3fd4240a3cc766ff16a1b4 100644 (file)
@@ -1,3 +1,11 @@
+2007-09-26  Joseph Myers  <joseph@codesourcery.com>
+
+       PR c/25309
+       * gcc.dg/large-size-array-2.c: Expect diagnostic for too-large
+       array.
+       * gcc.dg/large-size-array-4.c: New.  Copy of large-size-array-2.c
+       without -O2.
+
 2007-09-26  Richard Guenther  <rguenther@suse.de>
 
        PR tree-optimization/30375
index 6ac31d11af4261f8a7d9ebcd3be87e21c2f4a1d5..5411b838fac066a6166ef9e26582ef020b852297 100644 (file)
@@ -4,4 +4,4 @@
 static char * name[] = {
     [0x80000000]  = "bar"
   };
-
+/* { dg-error "too large" "" { target { ! lp64 } } 6 } */
diff --git a/gcc/testsuite/gcc.dg/large-size-array-4.c b/gcc/testsuite/gcc.dg/large-size-array-4.c
new file mode 100644 (file)
index 0000000..020d57e
--- /dev/null
@@ -0,0 +1,7 @@
+/* PR c/25309 */
+/* { dg-do compile } */
+/* { dg-options "" } */
+static char * name[] = {
+    [0x80000000]  = "bar"
+  };
+/* { dg-error "too large" "" { target { ! lp64 } } 6 } */