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]

[RFA] Fix PR 598 and PR 776


Since at least as far back as 2.95.x, GCC ICEs if an object of
sufficiently large size is allocated on the stack.

This is because assign_stack_temp_for_type expects a size of -1
(returned indirectly from int_size_for_type) to mean an object of
unknown size has been allocated on the stack, an ICE condition.

However, in fact -1 has an overloaded meaning: it also means object
too large (larger than the positive range of HOST_WIDE_INT).

This patch + testcase catches such cases before
assign_stack_temp_for_type sees -1, emits an error, and allocates a
small object instead to allow the compilation to continue.

Bootstrapping x86 Linux.  OK to commit?

Neil.

	* function.c (assign_temp): Recover gracefully when stack
	objects are too large.
	* testsuite/gcc.dg/largeobj.c: New test.

Index: function.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/function.c,v
retrieving revision 1.319
diff -u -p -r1.319 function.c
--- function.c	2001/10/23 22:59:15	1.319
+++ function.c	2001/10/26 21:58:34
@@ -849,14 +849,23 @@ assign_temp (type, keep, memory_required
       if (size == 0)
 	size = 1;
 
-      /* Unfortunately, we don't yet know how to allocate variable-sized
-	 temporaries.  However, sometimes we have a fixed upper limit on
-	 the size (which is stored in TYPE_ARRAY_MAX_SIZE) and can use that
-	 instead.  This is the case for Chill variable-sized strings.  */
-      if (size == -1 && TREE_CODE (type) == ARRAY_TYPE
-	  && TYPE_ARRAY_MAX_SIZE (type) != NULL_TREE
-	  && host_integerp (TYPE_ARRAY_MAX_SIZE (type), 1))
-	size = tree_low_cst (TYPE_ARRAY_MAX_SIZE (type), 1);
+      if (size == -1)
+	{
+	  if (TYPE_SIZE_UNIT (TYPE_MAIN_VARIANT (type)) != 0)
+	    {
+	      error ("object too large for the stack");
+	      size = 1;
+	    }
+	  /* Unfortunately, we don't yet know how to allocate
+	     variable-sized temporaries.  However, sometimes we have a
+	     fixed upper limit on the size (which is stored in
+	     TYPE_ARRAY_MAX_SIZE) and can use that instead.  This is
+	     the case for Chill variable-sized strings.  */
+	  else if (TREE_CODE (type) == ARRAY_TYPE
+		   && TYPE_ARRAY_MAX_SIZE (type) != NULL_TREE
+		   && host_integerp (TYPE_ARRAY_MAX_SIZE (type), 1))
+	    size = tree_low_cst (TYPE_ARRAY_MAX_SIZE (type), 1);
+	}
 
       tmp = assign_stack_temp_for_type (mode, size, keep, type);
       return tmp;
Index: testsuite/gcc.dg/largeobj.c
===================================================================
RCS file: largeobj.c
diff -N largeobj.c
--- /dev/null	Tue May  5 13:32:27 1998
+++ largeobj.c	Fri Oct 26 14:58:34 2001
@@ -0,0 +1,11 @@
+/* PRs 598 and 776 - ICE when declaring large objects on the stack.  */
+
+/* Because we need to pick a definite size for the array, this test
+   only overflows "properly" on 32-bit machines.  */
+
+/* { dg-do compile { target i?86-*-* } } */
+
+int main()
+{
+  int a[540000000];		/* { dg-error "too large" } */
+}


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