From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16100 invoked by alias); 18 Feb 2015 02:22:53 -0000 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 Received: (qmail 16027 invoked by uid 48); 18 Feb 2015 02:22:49 -0000 From: "solar-gcc at openwall dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/59124] [4.8/4.9/5 Regression] Wrong warnings "array subscript is above array bounds" Date: Wed, 18 Feb 2015 02:22:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 4.8.3 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: solar-gcc at openwall dot com X-Bugzilla-Status: NEW X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: 4.8.5 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: cc Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2015-02/txt/msg01952.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59124 Alexander Peslyak changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |solar-gcc at openwall dot com --- Comment #8 from Alexander Peslyak --- Here's another testcase: $ gcc -S -Wall -O2 -funroll-loops testcase.c testcase.c: In function 'DES_std_set_key': testcase.c:14:17: warning: array subscript is above array bounds [-Warray-bounds] while (DES_key[i++]) k += 2; ^ =============== 8< =============== static int DES_KS_updates; static char DES_key[16]; void DES_std_set_key(char *key) { int i, j, k, l; j = key[0]; for (k = i = 0; (l = DES_key[i]) && (j = key[i]); i++) ; if (!j) { j = i; while (DES_key[i++]) k += 2; } if (k < j && ++DES_KS_updates) { } DES_key[0] = key[0]; } =============== >8 =============== GCC 4.7.4 and below report no warning, 4.8.0 and 4.9.2 report the warning above. Either -O2 -funroll-loops or -O3 result in the warning; simple -O2 does not. While i++ could potentially run beyond the end of DES_key[], depending on what's in DES_key[] and key[], this isn't the case in the program this snippet is taken from (and simplified), whereas the warning definitively claims "is" rather than "might be". For comparison, Dmitry's first testcase (from this bug's description) results in no warning with -O2 -funroll-loops (but does give the warning to me with -O3, as reported by Dmitry), whereas his second testcase (from comment 2) also reports the warning with -O2 -funroll-loops (but not with simple -O2). I tested this with 4.9.2. I hope this is similar enough to add to this bug (same affected versions, one of the two testcases also affected by -funroll-loops).