c/9516: [2003-02-01] Internal error when using a big array

Christian Ehrhardt ehrhardt@mathematik.uni-ulm.de
Fri Apr 4 17:48:00 GMT 2003


http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=9516

Hi,

this PR is about a segfault when initializing an array like this:

unsigned char tab[] = { 1,2,3,4,<several million initializer element> };

The reason is a stack overflow because the initializer elements are
in a TREE_LIST and this list is passed to expr.c:safe_from_p which
does an infinite recursion in this piece of code:

    case 'x':
      if (TREE_CODE (exp) == TREE_LIST)
        return ((TREE_VALUE (exp) == 0
                 || safe_from_p (x, TREE_VALUE (exp), 0))
                && (TREE_CHAIN (exp) == 0
                    || safe_from_p (x, TREE_CHAIN (exp), 0)));

I guess that rewriting this as:
    case 'x':
      if (TREE_CODE (exp) == TREE_LIST)
	{
	  tree tmp;
	  for (tmp = exp; tmp; tmp = TREE_CHAIN(tmp))
	    {
	      if (TREE_VALUE(exp) != 0 && !safe_from_p (x, TREE_VALUE (tmp), 0))
		return 0;
	    }
	  return 1;
	}

should fix this PR. I'll bootstrap and regtest.

   regards  Christian

-- 
THAT'S ALL FOLKS!



More information about the Gcc-bugs mailing list