This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Patch for ICE on initialising VLAs


Initialising a variable-length array (which is not allowed) will
generate a tree checking ICE (covered up by "confused by earlier
errors") because it is expected that constructor_max_index is an
INTEGER_CST to which tree_int_cst_lt can be applied.  This patch makes
it be an INTEGER_CST in such cases; a proper error for initialising a
VLA is already given (and spurious errors - better than having an ICE
- may also occur).

Bootstrapped with no regressions on i686-pc-linux-gnu.  Applied to
mainline.

2001-12-03  Joseph S. Myers  <jsm28@cam.ac.uk>

	* c-typeck.c (really_start_incremental_init, push_init_level):
	Avoid constructor_max_index being other than an INTEGER_CST.

testsuite:
2001-12-03  Joseph S. Myers  <jsm28@cam.ac.uk>

	* gcc.dg/vla-init-1.c: New test.

--- c-typeck.c.orig	Thu Nov  8 02:11:40 2001
+++ c-typeck.c	Sun Dec  2 21:44:07 2001
@@ -5259,6 +5259,13 @@ really_start_incremental_init (type)
 	      && TYPE_SIZE (constructor_type))
 	    constructor_max_index = build_int_2 (-1, -1);
 
+	  /* constructor_max_index needs to be an INTEGER_CST.  Attempts
+	     to initialize VLAs will cause an proper error; avoid tree
+	     checking errors as well by setting a safe value.  */
+	  if (constructor_max_index
+	      && TREE_CODE (constructor_max_index) != INTEGER_CST)
+	    constructor_max_index = build_int_2 (-1, -1);
+
 	  constructor_index
 	    = convert (bitsizetype,
 		       TYPE_MIN_VALUE (TYPE_DOMAIN (constructor_type)));
@@ -5424,6 +5431,13 @@ push_init_level (implicit)
 	  /* Detect non-empty initializations of zero-length arrays.  */
 	  if (constructor_max_index == NULL_TREE
 	      && TYPE_SIZE (constructor_type))
+	    constructor_max_index = build_int_2 (-1, -1);
+
+	  /* constructor_max_index needs to be an INTEGER_CST.  Attempts
+	     to initialize VLAs will cause an proper error; avoid tree
+	     checking errors as well by setting a safe value.  */
+	  if (constructor_max_index
+	      && TREE_CODE (constructor_max_index) != INTEGER_CST)
 	    constructor_max_index = build_int_2 (-1, -1);
 
 	  constructor_index
--- testsuite/gcc.dg/vla-init-1.c.orig	Mon Mar 26 23:57:02 2001
+++ testsuite/gcc.dg/vla-init-1.c	Sun Dec  2 22:02:48 2001
@@ -0,0 +1,13 @@
+/* Test for tree-checking error when initializing a variable-length array
+   (not allowed): constructor_max_index needs to be an INTEGER_CST.  */
+/* Origin: Joseph Myers <jsm28@cam.ac.uk>.  */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+int a;
+
+void
+foo (void)
+{
+  int x[a] = { 1 }; /* { dg-error "init" "VLA init" } */
+}

-- 
Joseph S. Myers
jsm28@cam.ac.uk


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]