public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/53198] New: [4.6 Regression] gcc wrongly emits "array subscript is above array bounds" for simple arrays
@ 2012-05-02 18:35 vapier at gentoo dot org
  2012-05-02 19:06 ` [Bug c/53198] " manu at gcc dot gnu.org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: vapier at gentoo dot org @ 2012-05-02 18:35 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 53198
           Summary: [4.6 Regression] gcc wrongly emits "array subscript is
                    above array bounds" for simple arrays
    Classification: Unclassified
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: vapier@gentoo.org
                CC: toolchain@gentoo.org
            Target: x86_64-linux-gnu


simple code that processes arrays based on NULL terminator rather than
ARRAY_SIZE

$ cat test.c
void *devices[] = { 0, };
int main()
{
        int i;
        for (i = 0; devices[i]; i++)
                ;
        return 0;
}

$ gcc -Warray-bounds -O2 test.c 
test.c: In function 'main':
test.c:5:21: warning: array subscript is above array bounds [-Warray-bounds]

looks like it started failing with 4.6.0 ... older versions are fine.


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

* [Bug c/53198] [4.6 Regression] gcc wrongly emits "array subscript is above array bounds" for simple arrays
  2012-05-02 18:35 [Bug c/53198] New: [4.6 Regression] gcc wrongly emits "array subscript is above array bounds" for simple arrays vapier at gentoo dot org
@ 2012-05-02 19:06 ` manu at gcc dot gnu.org
  2012-05-03 10:47 ` [Bug tree-optimization/53198] [4.6/4.7 " rguenth at gcc dot gnu.org
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: manu at gcc dot gnu.org @ 2012-05-02 19:06 UTC (permalink / raw)
  To: gcc-bugs

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

Manuel López-Ibáñez <manu at gcc dot gnu.org> changed:

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

--- Comment #1 from Manuel López-Ibáñez <manu at gcc dot gnu.org> 2012-05-02 19:06:15 UTC ---
gcc version 4.8.0 20120430 (experimental) [trunk revision 186957] (GCC) is also
fine.


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

* [Bug tree-optimization/53198] [4.6/4.7 Regression] gcc wrongly emits "array subscript is above array bounds" for simple arrays
  2012-05-02 18:35 [Bug c/53198] New: [4.6 Regression] gcc wrongly emits "array subscript is above array bounds" for simple arrays vapier at gentoo dot org
  2012-05-02 19:06 ` [Bug c/53198] " manu at gcc dot gnu.org
@ 2012-05-03 10:47 ` rguenth at gcc dot gnu.org
  2012-05-29 14:33 ` rguenth at gcc dot gnu.org
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu.org @ 2012-05-03 10:47 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Guenther <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2012-05-03
          Component|c                           |tree-optimization
            Summary|[4.6 Regression] gcc        |[4.6/4.7 Regression] gcc
                   |wrongly emits "array        |wrongly emits "array
                   |subscript is above array    |subscript is above array
                   |bounds" for simple arrays   |bounds" for simple arrays
     Ever Confirmed|0                           |1

--- Comment #2 from Richard Guenther <rguenth at gcc dot gnu.org> 2012-05-03 10:46:30 UTC ---
Confirmed.  This is because of loop header copying doing

<bb 2>:
  D.1711_8 = devices[0];
  if (D.1711_8 != 0B)
    goto <bb 3>;
  else
    goto <bb 5>;

<bb 3>:
  i_7 = 0;

<bb 4>:
  # i_9 = PHI <0(3), i_4(4)>
  i_4 = i_9 + 1;
  D.1711_3 = devices[i_4];
  if (D.1711_3 != 0B)
    goto <bb 4>;
  else
    goto <bb 5>;

thus VRP sees that the access in the loop uses indices of [1, INF] which
is out-of bounds.  In 4.8 we recognize that the loop can only run once
(because of the initializer size) and optimize the variable array access
away.


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

* [Bug tree-optimization/53198] [4.6/4.7 Regression] gcc wrongly emits "array subscript is above array bounds" for simple arrays
  2012-05-02 18:35 [Bug c/53198] New: [4.6 Regression] gcc wrongly emits "array subscript is above array bounds" for simple arrays vapier at gentoo dot org
  2012-05-02 19:06 ` [Bug c/53198] " manu at gcc dot gnu.org
  2012-05-03 10:47 ` [Bug tree-optimization/53198] [4.6/4.7 " rguenth at gcc dot gnu.org
@ 2012-05-29 14:33 ` rguenth at gcc dot gnu.org
  2012-07-16  7:28 ` Petr.Salinger at seznam dot cz
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu.org @ 2012-05-29 14:33 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Guenther <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P2
   Target Milestone|---                         |4.6.4


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

* [Bug tree-optimization/53198] [4.6/4.7 Regression] gcc wrongly emits "array subscript is above array bounds" for simple arrays
  2012-05-02 18:35 [Bug c/53198] New: [4.6 Regression] gcc wrongly emits "array subscript is above array bounds" for simple arrays vapier at gentoo dot org
                   ` (2 preceding siblings ...)
  2012-05-29 14:33 ` rguenth at gcc dot gnu.org
@ 2012-07-16  7:28 ` Petr.Salinger at seznam dot cz
  2012-10-23 22:33 ` manu at gcc dot gnu.org
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Petr.Salinger at seznam dot cz @ 2012-07-16  7:28 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Petr.Salinger at seznam dot cz 2012-07-16 07:28:26 UTC ---
Created attachment 27801
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=27801
another testcase - from xorg mouse driver


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

* [Bug tree-optimization/53198] [4.6/4.7 Regression] gcc wrongly emits "array subscript is above array bounds" for simple arrays
  2012-05-02 18:35 [Bug c/53198] New: [4.6 Regression] gcc wrongly emits "array subscript is above array bounds" for simple arrays vapier at gentoo dot org
                   ` (3 preceding siblings ...)
  2012-07-16  7:28 ` Petr.Salinger at seznam dot cz
@ 2012-10-23 22:33 ` manu at gcc dot gnu.org
  2012-12-18 15:16 ` rguenth at gcc dot gnu.org
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: manu at gcc dot gnu.org @ 2012-10-23 22:33 UTC (permalink / raw)
  To: gcc-bugs


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

Manuel López-Ibáñez <manu at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to fail|                            |4.8.0

--- Comment #4 from Manuel López-Ibáñez <manu at gcc dot gnu.org> 2012-10-23 22:33:15 UTC ---
(In reply to comment #3)
> Created attachment 27801 [details]
> another testcase - from xorg mouse driver

This warns with GCC 4.8 r192379:

pr53198.c: In function ‘CheckProtocol’:
pr53198.c:35:30: warning: array subscript is above array bounds
[-Warray-bounds]
     for (i = 0; internalNames[i]; i++)
                              ^

It doesn't warn with gcc 4.5.1


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

* [Bug tree-optimization/53198] [4.6/4.7 Regression] gcc wrongly emits "array subscript is above array bounds" for simple arrays
  2012-05-02 18:35 [Bug c/53198] New: [4.6 Regression] gcc wrongly emits "array subscript is above array bounds" for simple arrays vapier at gentoo dot org
                   ` (4 preceding siblings ...)
  2012-10-23 22:33 ` manu at gcc dot gnu.org
@ 2012-12-18 15:16 ` rguenth at gcc dot gnu.org
  2013-04-12 15:16 ` [Bug tree-optimization/53198] [4.7 " jakub at gcc dot gnu.org
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu.org @ 2012-12-18 15:16 UTC (permalink / raw)
  To: gcc-bugs


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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to work|                            |4.8.0
      Known to fail|4.7.0, 4.8.0                |4.7.2

--- Comment #5 from Richard Biener <rguenth at gcc dot gnu.org> 2012-12-18 15:16:16 UTC ---
(In reply to comment #4)
> (In reply to comment #3)
> > Created attachment 27801 [details]
> > another testcase - from xorg mouse driver
> 
> This warns with GCC 4.8 r192379:
> 
> pr53198.c: In function ‘CheckProtocol’:
> pr53198.c:35:30: warning: array subscript is above array bounds
> [-Warray-bounds]
>      for (i = 0; internalNames[i]; i++)
>                               ^
> 
> It doesn't warn with gcc 4.5.1

Doesn't warn any longer on trunk.


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

* [Bug tree-optimization/53198] [4.7 Regression] gcc wrongly emits "array subscript is above array bounds" for simple arrays
  2012-05-02 18:35 [Bug c/53198] New: [4.6 Regression] gcc wrongly emits "array subscript is above array bounds" for simple arrays vapier at gentoo dot org
                   ` (5 preceding siblings ...)
  2012-12-18 15:16 ` rguenth at gcc dot gnu.org
@ 2013-04-12 15:16 ` jakub at gcc dot gnu.org
  2013-10-14 10:14 ` Emmanuel.Thome at inria dot fr
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: jakub at gcc dot gnu.org @ 2013-04-12 15:16 UTC (permalink / raw)
  To: gcc-bugs


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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|4.6.4                       |4.7.4

--- Comment #6 from Jakub Jelinek <jakub at gcc dot gnu.org> 2013-04-12 15:15:57 UTC ---
GCC 4.6.4 has been released and the branch has been closed.


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

* [Bug tree-optimization/53198] [4.7 Regression] gcc wrongly emits "array subscript is above array bounds" for simple arrays
  2012-05-02 18:35 [Bug c/53198] New: [4.6 Regression] gcc wrongly emits "array subscript is above array bounds" for simple arrays vapier at gentoo dot org
                   ` (6 preceding siblings ...)
  2013-04-12 15:16 ` [Bug tree-optimization/53198] [4.7 " jakub at gcc dot gnu.org
@ 2013-10-14 10:14 ` Emmanuel.Thome at inria dot fr
  2013-10-14 10:43 ` paolo.carlini at oracle dot com
  2014-06-12 13:07 ` rguenth at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: Emmanuel.Thome at inria dot fr @ 2013-10-14 10:14 UTC (permalink / raw)
  To: gcc-bugs

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

Emmanuel Thomé <Emmanuel.Thome at inria dot fr> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |Emmanuel.Thome at inria dot fr

--- Comment #7 from Emmanuel Thomé <Emmanuel.Thome at inria dot fr> ---

Hi,

Seems to me that the bug is still present in 4.7.3 (stock version,
x86_64-unknown-linux-gnu)

int foo(unsigned long t)        /* implicit promise that t != 0 */
{
    unsigned long a[2] = {0, t};
    int i;
    for(i = 1 ; !a[i] ; i++);
    return a[i];
}

int bar(unsigned long t)        /* implicit promise that t != 0 */
{
    unsigned long a[2] = {0, t};
    int i;
    for(i = 0 ; !a[++i] ; );
    return a[i];
}

$ gcc -c -W -Wall -O2 b.c
b.c: In function ‘foo’:
b.c:5:19: warning: array subscript is above array bounds [-Warray-bounds]


Interestingly, the two functions are equivalent as far as I can tell (sorry for
headaches induced by contrived control), and behave differently with 4.7.3.
Both with respect to the fact that only one triggers the warning, and also that
assembly code generated differs slightly.

4.8.1 behaves fine, and optimizes everything away as expected.
>From gcc-bugs-return-431644-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Mon Oct 14 10:22:47 2013
Return-Path: <gcc-bugs-return-431644-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 21871 invoked by alias); 14 Oct 2013 10:22:47 -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 21833 invoked by uid 48); 14 Oct 2013 10:22:44 -0000
From: "ebotcazou at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug bootstrap/58509] [4.9 regression] ICE in calc_dfs_tree, at dominance.c:397 during Ada runtime build
Date: Mon, 14 Oct 2013 10:22:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: bootstrap
X-Bugzilla-Version: 4.9.0
X-Bugzilla-Keywords:
X-Bugzilla-Severity: major
X-Bugzilla-Who: ebotcazou at gcc dot gnu.org
X-Bugzilla-Status: RESOLVED
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: ebotcazou at gcc dot gnu.org
X-Bugzilla-Target-Milestone: 4.9.0
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields: bug_status resolution
Message-ID: <bug-58509-4-uXp5yCvnVa@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-58509-4@http.gcc.gnu.org/bugzilla/>
References: <bug-58509-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: 2013-10/txt/msg00788.txt.bz2
Content-length: 443

http://gcc.gnu.org/bugzilla/show_bug.cgi?idX509

Eric Botcazou <ebotcazou at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #7 from Eric Botcazou <ebotcazou at gcc dot gnu.org> ---
Sorry for the delay.


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

* [Bug tree-optimization/53198] [4.7 Regression] gcc wrongly emits "array subscript is above array bounds" for simple arrays
  2012-05-02 18:35 [Bug c/53198] New: [4.6 Regression] gcc wrongly emits "array subscript is above array bounds" for simple arrays vapier at gentoo dot org
                   ` (7 preceding siblings ...)
  2013-10-14 10:14 ` Emmanuel.Thome at inria dot fr
@ 2013-10-14 10:43 ` paolo.carlini at oracle dot com
  2014-06-12 13:07 ` rguenth at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-10-14 10:43 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Nobody pretended it's fixed in 4.7.x.


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

* [Bug tree-optimization/53198] [4.7 Regression] gcc wrongly emits "array subscript is above array bounds" for simple arrays
  2012-05-02 18:35 [Bug c/53198] New: [4.6 Regression] gcc wrongly emits "array subscript is above array bounds" for simple arrays vapier at gentoo dot org
                   ` (8 preceding siblings ...)
  2013-10-14 10:43 ` paolo.carlini at oracle dot com
@ 2014-06-12 13:07 ` rguenth at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu.org @ 2014-06-12 13:07 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53198

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED
   Target Milestone|4.7.4                       |4.8.0
      Known to fail|                            |4.7.4

--- Comment #9 from Richard Biener <rguenth at gcc dot gnu.org> ---
Fixed in 4.8.0.


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

end of thread, other threads:[~2014-06-12 13:07 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-05-02 18:35 [Bug c/53198] New: [4.6 Regression] gcc wrongly emits "array subscript is above array bounds" for simple arrays vapier at gentoo dot org
2012-05-02 19:06 ` [Bug c/53198] " manu at gcc dot gnu.org
2012-05-03 10:47 ` [Bug tree-optimization/53198] [4.6/4.7 " rguenth at gcc dot gnu.org
2012-05-29 14:33 ` rguenth at gcc dot gnu.org
2012-07-16  7:28 ` Petr.Salinger at seznam dot cz
2012-10-23 22:33 ` manu at gcc dot gnu.org
2012-12-18 15:16 ` rguenth at gcc dot gnu.org
2013-04-12 15:16 ` [Bug tree-optimization/53198] [4.7 " jakub at gcc dot gnu.org
2013-10-14 10:14 ` Emmanuel.Thome at inria dot fr
2013-10-14 10:43 ` paolo.carlini at oracle dot com
2014-06-12 13:07 ` rguenth 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).