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

* [Bug middle-end/60121] gcc does not warn an obvious out-of-bound array access at -O0 and -O1
  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 ` pinskia at gcc dot gnu.org
  2014-02-09  0:08 ` su at cs dot ucdavis.edu
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2014-02-08 23:41 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|c                           |middle-end

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I think this is expected. out of bounds warnings come not from the front-end
but the middle-end and are designed not to warn about in dead code.  This code
is dead as a != 0 is always false.


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

* [Bug middle-end/60121] gcc does not warn an obvious out-of-bound array access at -O0 and -O1
  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
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: su at cs dot ucdavis.edu @ 2014-02-09  0:08 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Zhendong Su <su at cs dot ucdavis.edu> ---
(In reply to Andrew Pinski from comment #2)
> I think this is expected. out of bounds warnings come not from the front-end
> but the middle-end and are designed not to warn about in dead code.  This
> code is dead as a != 0 is always false.

Andrew, it's actually the complete opposite with this testcase. 

At -O0 and -O1, gcc unlikely knows that the out-of-bound array access is dead,
so the warning should be issued, but it's not. 

On the other hand, at -Os and above, gcc likely knows that the out-of-bound
array access is dead, but it warns.


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

* [Bug middle-end/60121] gcc does not warn an obvious out-of-bound array access at -O0 and -O1
  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
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2014-02-09  0:14 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |DUPLICATE

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Actually the reason for the warning is due to LIM pulling the out of bounds
access out of the loop, the same reason why bug 60115 fails.  It is just
showing the bug a different way.

*** This bug has been marked as a duplicate of bug 60115 ***


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

* [Bug middle-end/60121] gcc does not warn an obvious out-of-bound array access at -O0 and -O1
  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
                   ` (2 preceding siblings ...)
  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
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: su at cs dot ucdavis.edu @ 2014-02-09  0:18 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Zhendong Su <su at cs dot ucdavis.edu> ---
(In reply to Andrew Pinski from comment #4)
> Actually the reason for the warning is due to LIM pulling the out of bounds
> access out of the loop, the same reason why bug 60115 fails.  It is just
> showing the bug a different way.
> 
> *** This bug has been marked as a duplicate of bug 60115 ***

Andrew, you completely lost me ...  

Please note that this warning issue affects ALL earlier versions of GCC too,
but 60115 only for the current 4.8 branch and the main trunk. 

Please check the report carefully. Thanks.


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

* [Bug middle-end/60121] gcc does not warn an obvious out-of-bound array access at -O0 and -O1
  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
                   ` (3 preceding siblings ...)
  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
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: chengniansun at gmail dot com @ 2014-02-09  0:32 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Chengnian Sun <chengniansun at gmail dot com> ---
The test case can be further reduced to the following code, which is NOT dead
or dependent on bug 60115. 

int b[1];
int f() {
  return b[9999];
}


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

* [Bug middle-end/60121] gcc does not warn an obvious out-of-bound array access at -O0 and -O1
  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
                   ` (4 preceding siblings ...)
  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
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2014-02-09  0:47 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Chengnian Sun from comment #6)
> The test case can be further reduced to the following code, which is NOT
> dead or dependent on bug 60115. 
> 
> int b[1];
> int f() {
>   return b[9999];
> }

Because we don't warn in the front-end.  That was on purpose.  I can find the
old bug reports of why we don't want to warn in the front-end.  The warning
only happens in VPR which is only enabled for -O2 and above (-Os is -O2 plus
optimize for size really).


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

* [Bug middle-end/60121] gcc does not warn an obvious out-of-bound array access at -O0 and -O1
  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
                   ` (5 preceding siblings ...)
  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
  7 siblings, 0 replies; 9+ messages in thread
From: chengniansun at gmail dot com @ 2014-02-09  1:27 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from Chengnian Sun <chengniansun at gmail dot com> ---
(In reply to Andrew Pinski from comment #7)
> (In reply to Chengnian Sun from comment #6)
> > The test case can be further reduced to the following code, which is NOT
> > dead or dependent on bug 60115. 
> > 
> > int b[1];
> > int f() {
> >   return b[9999];
> > }
> 
> Because we don't warn in the front-end.  That was on purpose.  I can find
> the old bug reports of why we don't want to warn in the front-end.  The
> warning only happens in VPR which is only enabled for -O2 and above (-Os is
> -O2 plus optimize for size really).

Thanks. Is it possible to enable vrp with -ftree-vrp at -O0 level? Therefore
the user can get this warning even when the code is not optimized?


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

* [Bug middle-end/60121] gcc does not warn an obvious out-of-bound array access at -O0 and -O1
  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
                   ` (6 preceding siblings ...)
  2014-02-09  1:27 ` chengniansun at gmail dot com
@ 2014-02-09  6:39 ` jakub at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2014-02-09  6:39 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #9 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
No.  VRP isn't really a cheap pass and for -O0 the most important thing is
compile time speed.  GCC has never guaranteed the same warnings between
optimization levels, for frontend warnings it is sometimes possible to have the
same warnings, but for middle-end warnings it is not possible and never a goal.
Think say about uninitialized warnings, some of them heavily depend on which
functions are inlined and which are not.


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