public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/101671] New: pr83510 fails because threader confuses -Warray-bounds
@ 2021-07-29 10:20 aldyh at gcc dot gnu.org
  2021-07-29 16:04 ` [Bug middle-end/101671] pr83510 fails with -Os " msebor at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: aldyh at gcc dot gnu.org @ 2021-07-29 10:20 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 101671
           Summary: pr83510 fails because threader confuses -Warray-bounds
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: aldyh at gcc dot gnu.org
  Target Milestone: ---

After my rewrite of the backwards threader with the ranger (commit
2e96b5f14e4025691b57d2301d71aa6092ed44bc), gcc.c-torture/compile/pr83510.c is
failing.

Here's a quote from my analysis in the test itself:

/*  This test is XFAILed because thread1 threads a switch statement
    such that the various cases have been split into different
    independent blocks.  One of these blocks exposes an arr[i_27]
    which is later propagated by VRP to be arr[10].  This is an
    invalid access, but the array bounds code doesn't know it is an
    unreachable path.

    However, it is not until dom2 that we "know" that the value of the
    switch index is such that the path to arr[10] is unreachable.  For
    that matter, it is not until dom3 that we remove the unreachable
    path.


    See:
    https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83510
    https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83312

    It's not until here that ranger "knows" that the path is
    unreachable:

    thread1
    vrp1                <-- array bounds checking
    dce2
    stdarg
    cdce
    cselim
    copyprop
    ifcombine
    mergephi3           <-- too late
*/

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

* [Bug middle-end/101671] pr83510 fails with -Os because threader confuses -Warray-bounds
  2021-07-29 10:20 [Bug middle-end/101671] New: pr83510 fails because threader confuses -Warray-bounds aldyh at gcc dot gnu.org
@ 2021-07-29 16:04 ` msebor at gcc dot gnu.org
  2021-07-29 16:20 ` aldyh at redhat dot com
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-07-29 16:04 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |msebor at gcc dot gnu.org
   Last reconfirmed|                            |2021-07-29
           Keywords|                            |diagnostic
            Summary|pr83510 fails because       |pr83510 fails with -Os
                   |threader confuses           |because threader confuses
                   |-Warray-bounds              |-Warray-bounds
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW

--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
Confirmed.  I've extracted the test case that fails from the bigger test. 
Rather than xfailing the whole test I think it would be better to split out
just the failing case and/or xfail just that assertion.  Unless you expect the
others to start failing too due to some changes you still have planned?

$ cat a.c && gcc -Os -S -Wall a.c
extern int f (void);
extern void sink (unsigned int);

unsigned int a[10];

static unsigned int g (int i, int j)
{
  if (i == 9)
    return j;
  else if (i == 10)
    return a[i];    // no warning here
  return 0;
}

void test_g (int j)
{
  for (int i = 0; i < 10; i++)
    {
      if (f ())
        sink (g (i, j));
    }
}

static unsigned int h (int i, int j)
{
  switch (i)
    {
    case 9:
      return j;
    case 10:
      return a[i];  // { dg-bogus "-Warray-bounds" }
    }
  return 0;
}

void test_h (int j)
{
  for (int i = 0; i < 10; i++)
    {
      if (f ())
        sink (h (i, j));
    }
}
In function ‘h’,
    inlined from ‘test_h’ at a.c:41:2:
a.c:31:15: warning: array subscript 10 is above array bounds of ‘unsigned
int[10]’ [-Warray-bounds]
   31 |       return a[i];  // { dg-bogus "-Warray-bounds" }
      |              ~^~~
a.c: In function ‘test_h’:
a.c:4:14: note: while referencing ‘a’
    4 | unsigned int a[10];
      |              ^

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

* [Bug middle-end/101671] pr83510 fails with -Os because threader confuses -Warray-bounds
  2021-07-29 10:20 [Bug middle-end/101671] New: pr83510 fails because threader confuses -Warray-bounds aldyh at gcc dot gnu.org
  2021-07-29 16:04 ` [Bug middle-end/101671] pr83510 fails with -Os " msebor at gcc dot gnu.org
@ 2021-07-29 16:20 ` aldyh at redhat dot com
  2021-07-30 17:44 ` cvs-commit at gcc dot gnu.org
  2022-12-29 22:12 ` [Bug middle-end/101671] bogus -Warray-bounds on an unreachable switch case with -Os pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: aldyh at redhat dot com @ 2021-07-29 16:20 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Aldy Hernandez <aldyh at redhat dot com> ---
Yeah, that would be great.  Thanks!

On Thu, Jul 29, 2021 at 6:05 PM msebor at gcc dot gnu.org
<gcc-bugzilla@gcc.gnu.org> wrote:
>
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101671
>
> Martin Sebor <msebor at gcc dot gnu.org> changed:
>
>            What    |Removed                     |Added
> ----------------------------------------------------------------------------
>                  CC|                            |msebor at gcc dot gnu.org
>    Last reconfirmed|                            |2021-07-29
>            Keywords|                            |diagnostic
>             Summary|pr83510 fails because       |pr83510 fails with -Os
>                    |threader confuses           |because threader confuses
>                    |-Warray-bounds              |-Warray-bounds
>      Ever confirmed|0                           |1
>              Status|UNCONFIRMED                 |NEW
>
> --- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
> Confirmed.  I've extracted the test case that fails from the bigger test.
> Rather than xfailing the whole test I think it would be better to split out
> just the failing case and/or xfail just that assertion.  Unless you expect the
> others to start failing too due to some changes you still have planned?
>
> $ cat a.c && gcc -Os -S -Wall a.c
> extern int f (void);
> extern void sink (unsigned int);
>
> unsigned int a[10];
>
> static unsigned int g (int i, int j)
> {
>   if (i == 9)
>     return j;
>   else if (i == 10)
>     return a[i];    // no warning here
>   return 0;
> }
>
> void test_g (int j)
> {
>   for (int i = 0; i < 10; i++)
>     {
>       if (f ())
>         sink (g (i, j));
>     }
> }
>
> static unsigned int h (int i, int j)
> {
>   switch (i)
>     {
>     case 9:
>       return j;
>     case 10:
>       return a[i];  // { dg-bogus "-Warray-bounds" }
>     }
>   return 0;
> }
>
> void test_h (int j)
> {
>   for (int i = 0; i < 10; i++)
>     {
>       if (f ())
>         sink (h (i, j));
>     }
> }
> In function ‘h’,
>     inlined from ‘test_h’ at a.c:41:2:
> a.c:31:15: warning: array subscript 10 is above array bounds of ‘unsigned
> int[10]’ [-Warray-bounds]
>    31 |       return a[i];  // { dg-bogus "-Warray-bounds" }
>       |              ~^~~
> a.c: In function ‘test_h’:
> a.c:4:14: note: while referencing ‘a’
>     4 | unsigned int a[10];
>       |              ^
>
> --
> You are receiving this mail because:
> You reported the bug.
>

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

* [Bug middle-end/101671] pr83510 fails with -Os because threader confuses -Warray-bounds
  2021-07-29 10:20 [Bug middle-end/101671] New: pr83510 fails because threader confuses -Warray-bounds aldyh at gcc dot gnu.org
  2021-07-29 16:04 ` [Bug middle-end/101671] pr83510 fails with -Os " msebor at gcc dot gnu.org
  2021-07-29 16:20 ` aldyh at redhat dot com
@ 2021-07-30 17:44 ` cvs-commit at gcc dot gnu.org
  2022-12-29 22:12 ` [Bug middle-end/101671] bogus -Warray-bounds on an unreachable switch case with -Os pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-07-30 17:44 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Martin Sebor <msebor@gcc.gnu.org>:

https://gcc.gnu.org/g:0b3560d3a9f2b55ba4807f2b0f8cbbf6cee9e6e3

commit r12-2634-g0b3560d3a9f2b55ba4807f2b0f8cbbf6cee9e6e3
Author: Martin Sebor <msebor@redhat.com>
Date:   Fri Jul 30 11:41:02 2021 -0600

    Move failed part of a test to a new file [PR101671]

    Related:
    PR middle-end/101671 - pr83510 fails with -Os because threader confuses
-Warray-bounds

    gcc/testsuite:
            PR middle-end/101671
            * gcc.c-torture/compile/pr83510.c: Move test functions...
            * gcc.dg/Warray-bounds-87.c: ...to this file.

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

* [Bug middle-end/101671] bogus -Warray-bounds on an unreachable switch case with -Os
  2021-07-29 10:20 [Bug middle-end/101671] New: pr83510 fails because threader confuses -Warray-bounds aldyh at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2021-07-30 17:44 ` cvs-commit at gcc dot gnu.org
@ 2022-12-29 22:12 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-12-29 22:12 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Hmm, the xfail was removed with r12-4526-gd8edfadfc7a979 . Was this fixed then?

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

end of thread, other threads:[~2022-12-29 22:12 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-29 10:20 [Bug middle-end/101671] New: pr83510 fails because threader confuses -Warray-bounds aldyh at gcc dot gnu.org
2021-07-29 16:04 ` [Bug middle-end/101671] pr83510 fails with -Os " msebor at gcc dot gnu.org
2021-07-29 16:20 ` aldyh at redhat dot com
2021-07-30 17:44 ` cvs-commit at gcc dot gnu.org
2022-12-29 22:12 ` [Bug middle-end/101671] bogus -Warray-bounds on an unreachable switch case with -Os pinskia 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).