public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/60121] New: gcc does not warn an obvious out-of-bound array access at -O0 and -O1
@ 2014-02-08 23:15 su at cs dot ucdavis.edu
  2014-02-08 23:41 ` [Bug middle-end/60121] " pinskia at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: su at cs dot ucdavis.edu @ 2014-02-08 23:15 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60121

            Bug ID: 60121
           Summary: gcc does not warn an obvious out-of-bound array access
                    at -O0 and -O1
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: su at cs dot ucdavis.edu

For the given testcase below, gcc doesn't warn the out-of-bound array access at
-O0 and -O1, but does at -Os and above, while clang warns at all optimization
levels. Since the out-of-bound access is obvious, I wonder whether gcc should
also warn at -O0 and -O1. 

This affects the current gcc trunk and all earlier versions. 

$ gcc-trunk -v
Using built-in specs.
COLLECT_GCC=gcc-trunk
COLLECT_LTO_WRAPPER=/usr/local/gcc-trunk/libexec/gcc/x86_64-unknown-linux-gnu/4.9.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../gcc-trunk/configure --prefix=/usr/local/gcc-trunk
--enable-languages=c,c++ --disable-werror --enable-multilib
Thread model: posix
gcc version 4.9.0 20140208 (experimental) [trunk revision 207627] (GCC) 
$
$ gcc-trunk -Warray-bounds -O0 small.c
$ gcc-trunk -Warray-bounds -O1 small.c 
$     
$ gcc-trunk -Warray-bounds -Os small.c
small.c: In function ‘main’:
small.c:8:10: warning: array subscript is above array bounds [-Warray-bounds]
     if (b[613])
          ^
$
$ clang-trunk -Warray-bounds -O0 small.c
small.c:8:9: warning: array index 613 is past the end of the array (which
contains 1 element) [-Warray-bounds]
    if (b[613])
        ^ ~~~
small.c:1:1: note: array 'b' declared here
int a, b[1];
^
1 warning generated.
$
>From gcc-bugs-return-443091-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Sat Feb 08 23:16:27 2014
Return-Path: <gcc-bugs-return-443091-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 12957 invoked by alias); 8 Feb 2014 23:16:27 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 12931 invoked by uid 48); 8 Feb 2014 23:16:19 -0000
From: "su at cs dot ucdavis.edu" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/60121] gcc does not warn an obvious out-of-bound array access at -O0 and -O1
Date: Sat, 08 Feb 2014 23:16:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: c
X-Bugzilla-Version: 4.9.0
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: su at cs dot ucdavis.edu
X-Bugzilla-Status: UNCONFIRMED
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields:
Message-ID: <bug-60121-4-acQpdOSEdh@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-60121-4@http.gcc.gnu.org/bugzilla/>
References: <bug-60121-4@http.gcc.gnu.org/bugzilla/>
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: 2014-02/txt/msg00848.txt.bz2
Content-length: 266

http://gcc.gnu.org/bugzilla/show_bug.cgi?id`121

--- Comment #1 from Zhendong Su <su at cs dot ucdavis.edu> ---
Here is the testcase:


-------------------------


int a, b[1];

int
main ()
{
 lbl:
  for (; a; a--)
    if (b[613])
      goto lbl;

  return 0;
}


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2014-02-09  6:39 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-02-08 23:15 [Bug c/60121] New: gcc does not warn an obvious out-of-bound array access at -O0 and -O1 su at cs dot ucdavis.edu
2014-02-08 23:41 ` [Bug middle-end/60121] " pinskia at gcc dot gnu.org
2014-02-09  0:08 ` su at cs dot ucdavis.edu
2014-02-09  0:14 ` pinskia at gcc dot gnu.org
2014-02-09  0:18 ` su at cs dot ucdavis.edu
2014-02-09  0:32 ` chengniansun at gmail dot com
2014-02-09  0:47 ` pinskia at gcc dot gnu.org
2014-02-09  1:27 ` chengniansun at gmail dot com
2014-02-09  6:39 ` jakub at gcc dot gnu.org

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).