From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23005 invoked by alias); 14 Mar 2008 17:05:47 -0000 Received: (qmail 7311 invoked by uid 48); 14 Mar 2008 17:05:03 -0000 Date: Fri, 14 Mar 2008 17:05:00 -0000 Subject: [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 X-Bugzilla-Reason: CC Message-ID: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "karsten_burger at gmx dot de" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2008-03/txt/msg01135.txt.bz2 -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 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