public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/35587] New: -Warray-bounds does not work at all or does not find all trivial cases, and works only with -O2 or -O3
@ 2008-03-14 17:05 karsten_burger at gmx dot de
2008-03-14 17:08 ` [Bug c/35587] " karsten_burger at gmx dot de
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: karsten_burger at gmx dot de @ 2008-03-14 17:05 UTC (permalink / raw)
To: gcc-bugs
-Warray-bound is really a very interesting new feature, since me and some
colleagues recently spent many hours debugging a large legacy software, and
finally found C-char-array overrun errors as causes in most cases.
I used the following example:
#include <stdio.h>
int main()
{
int a[5];
a[-1] = 0; // line 5: error
a[+1] = 0; // ok
a[+5] = 0; // line 7: error
a[15] = 0; // line 8: error
printf("%d \n", a[15]); // line 9: error
int i=15;
printf("%d \n", a[i]); // line 11: error
return 0;
}
I used the following command line:
/usr/local/gcc-4.3.0/bin/gcc-4.3.0 bounds.c -O2 -Warray-bounds
1. Test:
I get no warning at compile time. I retried it using -O0, -O1, -O3, and there
is also no warning.
2. Test:
I changed integer i in line 10 to a value of 16.
Now I correctly get warnings in lines 5, 7, 8, 11, but not in line 9, stating
that the index is below/larger than the array permits.
Interestingly, the warnings are only issued if I am using -O2 or -O3, but not
with -O0 and not with -O1.
Conclusion:
* -Warray-bound is not reliable at the moment, it may or may not issue warnings
or no warnings at all.
* When it issues warnings, at line 8 of the example it finds the incorrect
assignment to a[15], but at line 9 not the incorrect use of a[15].
* When it issues warnings and I change line 9 to a[16], it reports lines 5, 7,
8, 9 but not line 11.
* If this option works only with -O2 and -O3 due to technical reasons, it
should be documented clearly to avoid frustration of the user.
--
Summary: -Warray-bounds does not work at all or does not find all
trivial cases, and works only with -O2 or -O3
Product: gcc
Version: 4.3.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: karsten_burger at gmx dot de
GCC build triplet: i686-linux-gnu
GCC host triplet: i686-linux-gnu
GCC target triplet: i686-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35587
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c/35587] -Warray-bounds does not work at all or does not find all trivial cases, and works only with -O2 or -O3
2008-03-14 17:05 [Bug c/35587] New: -Warray-bounds does not work at all or does not find all trivial cases, and works only with -O2 or -O3 karsten_burger at gmx dot de
@ 2008-03-14 17:08 ` karsten_burger at gmx dot de
2008-03-14 17:09 ` karsten_burger at gmx dot de
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: karsten_burger at gmx dot de @ 2008-03-14 17:08 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from karsten_burger at gmx dot de 2008-03-14 17:07 -------
Created an attachment (id=15321)
--> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=15321&action=view)
version which does not create any warning
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35587
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c/35587] -Warray-bounds does not work at all or does not find all trivial cases, and works only with -O2 or -O3
2008-03-14 17:05 [Bug c/35587] New: -Warray-bounds does not work at all or does not find all trivial cases, and works only with -O2 or -O3 karsten_burger at gmx dot de
2008-03-14 17:08 ` [Bug c/35587] " karsten_burger at gmx dot de
@ 2008-03-14 17:09 ` karsten_burger at gmx dot de
2008-03-17 13:16 ` [Bug c/35587] -Warray-bounds does not work at all or does not find all trivial cases, and :works " karsten_burger at gmx dot de
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: karsten_burger at gmx dot de @ 2008-03-14 17:09 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from karsten_burger at gmx dot de 2008-03-14 17:08 -------
Created an attachment (id=15322)
--> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=15322&action=view)
assembler output using gcc option -save-temps
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35587
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c/35587] -Warray-bounds does not work at all or does not find all trivial cases, and :works only with -O2 or -O3
2008-03-14 17:05 [Bug c/35587] New: -Warray-bounds does not work at all or does not find all trivial cases, and works only with -O2 or -O3 karsten_burger at gmx dot de
2008-03-14 17:08 ` [Bug c/35587] " karsten_burger at gmx dot de
2008-03-14 17:09 ` karsten_burger at gmx dot de
@ 2008-03-17 13:16 ` karsten_burger at gmx dot de
2008-03-17 14:06 ` rguenth at gcc dot gnu dot org
2008-05-03 9:44 ` nikos42 at gmail dot com
4 siblings, 0 replies; 6+ messages in thread
From: karsten_burger at gmx dot de @ 2008-03-17 13:16 UTC (permalink / raw)
To: gcc-bugs
--
karsten_burger at gmx dot de changed:
What |Removed |Added
----------------------------------------------------------------------------
Severity|normal |major
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35587
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c/35587] -Warray-bounds does not work at all or does not find all trivial cases, and :works only with -O2 or -O3
2008-03-14 17:05 [Bug c/35587] New: -Warray-bounds does not work at all or does not find all trivial cases, and works only with -O2 or -O3 karsten_burger at gmx dot de
` (2 preceding siblings ...)
2008-03-17 13:16 ` [Bug c/35587] -Warray-bounds does not work at all or does not find all trivial cases, and :works " karsten_burger at gmx dot de
@ 2008-03-17 14:06 ` rguenth at gcc dot gnu dot org
2008-05-03 9:44 ` nikos42 at gmail dot com
4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2008-03-17 14:06 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from rguenth at gcc dot gnu dot org 2008-03-17 14:05 -------
Hm, with gcc 4.2 I get
gcc-4.2 -c t.c -O2 -Wall
t.c: In function 'main':
t.c:5: warning: array subscript is below array bounds
t.c:7: warning: array subscript is above array bounds
t.c:8: warning: array subscript is above array bounds
t.c:9: warning: array subscript is above array bounds
(the warning in line 11 is missing as the constant is
propagated and the load from a[15] CSEd - this is a very hard
to fix implementation limit. You'd fix the case in line 9
and then the issue in line 11 would pop up.)
with 4.3 I indeed see
gcc-4.3 -c t.c -O2 -Wall
(nothing)
because all invalid stores are deleted from the code and the only
used value (a[15]) is propagated from the store a[15] = 0 and thus
replaced by the constant 0. Again a hard to fix implementation
issue - after all these invalid stores/loads invoke undefined
behavior which is why we just "optimized" them.
IMHO for these very simple cases the frontend should already warn
(even at -O0 and -O1) and not rely on the code surviving until VRP.
(The issue is that we in this way would also warn in dead code regions,
which may be a problem on its own).
Note this is not accepts-invalid as it is only undefined at runtime.
--
rguenth at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |mueller at gcc dot gnu dot
| |org, rguenth at gcc dot gnu
| |dot org
Severity|major |enhancement
Status|UNCONFIRMED |NEW
Ever Confirmed|0 |1
Keywords|accepts-invalid |
Last reconfirmed|0000-00-00 00:00:00 |2008-03-17 14:05:57
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35587
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c/35587] -Warray-bounds does not work at all or does not find all trivial cases, and :works only with -O2 or -O3
2008-03-14 17:05 [Bug c/35587] New: -Warray-bounds does not work at all or does not find all trivial cases, and works only with -O2 or -O3 karsten_burger at gmx dot de
` (3 preceding siblings ...)
2008-03-17 14:06 ` rguenth at gcc dot gnu dot org
@ 2008-05-03 9:44 ` nikos42 at gmail dot com
4 siblings, 0 replies; 6+ messages in thread
From: nikos42 at gmail dot com @ 2008-05-03 9:44 UTC (permalink / raw)
To: gcc-bugs
------- Comment #4 from nikos42 at gmail dot com 2008-05-03 09:43 -------
Confirmed with gcc 4.3.1. Complete version info:
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure linux gnu
Thread model: posix
gcc version 4.3.1 20080401 (prerelease) (Debian 4.3.0-3)
Regards,
Nicolas
--
nikos42 at gmail dot com changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |nikos42 at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35587
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2008-05-03 9:44 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-03-14 17:05 [Bug c/35587] New: -Warray-bounds does not work at all or does not find all trivial cases, and works only with -O2 or -O3 karsten_burger at gmx dot de
2008-03-14 17:08 ` [Bug c/35587] " karsten_burger at gmx dot de
2008-03-14 17:09 ` karsten_burger at gmx dot de
2008-03-17 13:16 ` [Bug c/35587] -Warray-bounds does not work at all or does not find all trivial cases, and :works " karsten_burger at gmx dot de
2008-03-17 14:06 ` rguenth at gcc dot gnu dot org
2008-05-03 9:44 ` nikos42 at gmail dot com
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).