[PATCH,testsuite] fix STACK_SIZE issue in pr23135.c

Nathan Froyd froydnj@codesourcery.com
Mon Jul 9 20:06:00 GMT 2007


The attached patch fixes an issue with pr23135.c and STACK_SIZE.  We
declare:

typedef struct { char c[STACK_SIZE/2]; } big_t;

thinking that we will only need one copy of big_t inside our main
function.  Except that we pass a big_t by value, so we need to copy it,
which means that we have two STACK_SIZE/2 objects on the stack, plus any
local variables, saved registers, etc. etc.  Therefore, our stack size
requirement winds up exceeding STACK_SIZE.  So we need to be a bit more
conservative in how big a big_t is, which is what this patch does.

It's possible that there may still be platforms on which this fails, but
this patch is at least an improvement on what we had before.

Tested on {i586,ppc,sparc}-wrs-vxworks with STACK_SIZE defined to be
192k.  The testcase failed on these platforms previously and passes with
the patch.  OK to commit?

-Nathan

2007-07-09  Nathan Froyd  <froydnj@codesourcery.com>

	* gcc.c-torture/execute/pr23135.c (big_t): Be more conservative
	in sizing the c array.
-------------- next part --------------
Index: gcc/testsuite/gcc.c-torture/execute/pr23135.c
===================================================================
--- gcc/testsuite/gcc.c-torture/execute/pr23135.c	(revision 176045)
+++ gcc/testsuite/gcc.c-torture/execute/pr23135.c	(working copy)
@@ -5,11 +5,17 @@
 #define STACK_SIZE (256*1024)
 #endif
 
-typedef struct { char c[STACK_SIZE/2]; } big_t;
-
 typedef int __attribute__((vector_size (8))) vecint;
 typedef int __attribute__((mode(SI))) siint;
 
+/* In the worst case, we need to allocate two of these on the stack
+   inside of 'main'--one for the actual variable and one for argument
+   passing.  However, we also need to make sure that there's a bit of
+   space available for local variables, saved registers, and the
+   like.  'main' needs eight 'vecint's; let's conservatively assume
+   that we need 512 'void *' stack slots too.  */
+typedef struct { char c[STACK_SIZE/2-8*sizeof (vecint)-512*sizeof (void*)]; } big_t;
+
 vecint i = { 150, 100 };
 vecint j = { 10, 13 };
 vecint k;


More information about the Gcc-patches mailing list