c/8268: no compile time array index checking
David Binderman
d.binderman@virgin.net
Sun Jan 26 16:06:00 GMT 2003
The following reply was made to PR c/8268; it has been noted by GNATS.
From: "David Binderman" <d.binderman@virgin.net>
To: <bangerth@dealii.org>,
<gcc-prs@gcc.gnu.org>,
<nobody@gcc.gnu.org>,
<gcc-gnats@gcc.gnu.org>,
<gcc-bugs@gcc.gnu.org>
Cc:
Subject: Re: c/8268: no compile time array index checking
Date: Sun, 26 Jan 2003 16:08:53 -0000
Hello there,
I tried out the suggested patch, and it seems ok, until I run
the gcc test suite, where I get problems on test
gcc.c-torture/execute/20010924-1.c
as shown
(gdb) r /tmp/1.i
Starting program:
/home/dcb/gnu/gcc321/results.check/lib/gcc-lib/i686-pc-linux-gnu/3.2.1/cc1
/tmp/1.i
main
Program received signal SIGSEGV, Segmentation fault.
0x080f12d3 in get_inner_reference (exp=0x40271700, pbitsize=0xbffff1ec,
pbitpos=0xbffff1f0, poffset=0xbffff1f4, pmode=0x0,
punsignedp=0x40016c60,
pvolatilep=0xbffff1fc) at ../../src/gcc-3.2.1/gcc/expr.c:5338
5338 || (TREE_CODE (TYPE_MAX_VALUE (domain)) ==
INTEGER_CST(gdb) list
5333
5334 if (domain && TREE_CODE (index) == INTEGER_CST)
5335 {
5336 if ((TREE_CODE (low_bound) == INTEGER_CST
5337 && tree_int_cst_lt(index, low_bound))
5338 || (TREE_CODE (TYPE_MAX_VALUE (domain)) ==
INTEGER_CST5339 && tree_int_cst_lt (TYPE_MAX_VALUE
(domain), index)
5340 /* Accesses after the end of arrays of size 0
(gcc5341 extension) and 1 are likely
intentional. */
5342 && !tree_int_cst_lt (TYPE_MAX_VALUE (domain),
(gdb)
Further, it seems a good idea if the warning message produced could be
enhanced to give a clue about the index value and the size of the array.
Something like
warning: array index '10' in array 'fred' of size '5' is not valid.
A possible second enhancement is to make sure that all six bugs in my
original demonstration case are found. The current version of the patch
only finds four of the six problems.
The supplied patch does seem to find bugs in the gcc321 source code,
however.
Regards
dcb
----- Original Message -----
From: <bangerth@dealii.org>
To: <d.binderman@virgin.net>; <gcc-bugs@gcc.gnu.org>; <gcc-prs@gcc.gnu.org>;
<nobody@gcc.gnu.org>
Sent: Wednesday, January 08, 2003 2:40 AM
Subject: Re: c/8268: no compile time array index checking
> Synopsis: no compile time array index checking
>
> State-Changed-From-To: open->analyzed
> State-Changed-By: bangerth
> State-Changed-When: Tue Jan 7 18:40:02 2003
> State-Changed-Why:
> Valid request. Falk even has a patch for that, but it
> does not seem to be in.
>
> In fact, the category should not be accepts-illegal, since
> the code is perfectly legal. It just does something
> undefined.
>
> W.
>
>
http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&p
r=8268
>
More information about the Gcc-prs
mailing list