public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/111365] New: Wrong code at -O3 since r13-1268-g8c99e307b20
@ 2023-09-11  7:25 shaohua.li at inf dot ethz.ch
  2023-09-11  8:21 ` [Bug tree-optimization/111365] " xry111 at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: shaohua.li at inf dot ethz.ch @ 2023-09-11  7:25 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 111365
           Summary: Wrong code at -O3 since r13-1268-g8c99e307b20
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: shaohua.li at inf dot ethz.ch
                CC: aldyh at redhat dot com
  Target Milestone: ---

gcc at -O3 produced the wrong code.

Bisected to r13-1268-g8c99e307b20

Compiler explorer: https://godbolt.org/z/5rb3sTG3E

$ cat a.c
int printf(const char *, ...);
int a, c, d, e = -1233286202, f = -1233286202;
short b, g, j;
int k(int l) {
  if (l <= 0 || &c + l > &d)
    return -1;
  return 0;
}
int m(int l) {
  int h = k(l);
  return h;
}
int main() {
  int i = 0;
  for (;
       (m(f + 1233286202) + e + (f + 1233286202) + 1233220671) + 65532U + i <
9;
       i++)
    g = 6;
  printf("%d\n", g);
}
$
$ gcc -O0 a.c && ./a.out
6
$ gcc -O3 a.c && ./a.out
0
$ gcc -fsanitize=address,undefined a.c && ./a.out
6
$

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

* [Bug tree-optimization/111365] Wrong code at -O3 since r13-1268-g8c99e307b20
  2023-09-11  7:25 [Bug c/111365] New: Wrong code at -O3 since r13-1268-g8c99e307b20 shaohua.li at inf dot ethz.ch
@ 2023-09-11  8:21 ` xry111 at gcc dot gnu.org
  2023-09-11  8:37 ` xry111 at gcc dot gnu.org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: xry111 at gcc dot gnu.org @ 2023-09-11  8:21 UTC (permalink / raw)
  To: gcc-bugs

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

Xi Ruoyao <xry111 at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |xry111 at gcc dot gnu.org
          Component|c                           |tree-optimization

--- Comment #1 from Xi Ruoyao <xry111 at gcc dot gnu.org> ---
Another ivopt issue (-fno-ivopt "fixes" it).

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

* [Bug tree-optimization/111365] Wrong code at -O3 since r13-1268-g8c99e307b20
  2023-09-11  7:25 [Bug c/111365] New: Wrong code at -O3 since r13-1268-g8c99e307b20 shaohua.li at inf dot ethz.ch
  2023-09-11  8:21 ` [Bug tree-optimization/111365] " xry111 at gcc dot gnu.org
@ 2023-09-11  8:37 ` xry111 at gcc dot gnu.org
  2023-09-11  8:41 ` xry111 at gcc dot gnu.org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: xry111 at gcc dot gnu.org @ 2023-09-11  8:37 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Xi Ruoyao <xry111 at gcc dot gnu.org> ---
int a, c, d, e = -1233286202, f = -1233286202;

...

if (l <= 0 || &c + l > &d)

I suppose this is invoking undefined behavior.

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

* [Bug tree-optimization/111365] Wrong code at -O3 since r13-1268-g8c99e307b20
  2023-09-11  7:25 [Bug c/111365] New: Wrong code at -O3 since r13-1268-g8c99e307b20 shaohua.li at inf dot ethz.ch
  2023-09-11  8:21 ` [Bug tree-optimization/111365] " xry111 at gcc dot gnu.org
  2023-09-11  8:37 ` xry111 at gcc dot gnu.org
@ 2023-09-11  8:41 ` xry111 at gcc dot gnu.org
  2023-09-11  8:43 ` xry111 at gcc dot gnu.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: xry111 at gcc dot gnu.org @ 2023-09-11  8:41 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Xi Ruoyao <xry111 at gcc dot gnu.org> ---
(In reply to Xi Ruoyao from comment #2)
> int a, c, d, e = -1233286202, f = -1233286202;
> 
> ...
> 
> if (l <= 0 || &c + l > &d)
> 
> I suppose this is invoking undefined behavior.

Nope, the problematic &c + l > &d should be short-cut by l <= 0.

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

* [Bug tree-optimization/111365] Wrong code at -O3 since r13-1268-g8c99e307b20
  2023-09-11  7:25 [Bug c/111365] New: Wrong code at -O3 since r13-1268-g8c99e307b20 shaohua.li at inf dot ethz.ch
                   ` (2 preceding siblings ...)
  2023-09-11  8:41 ` xry111 at gcc dot gnu.org
@ 2023-09-11  8:43 ` xry111 at gcc dot gnu.org
  2023-09-17 20:08 ` [Bug tree-optimization/111365] [13/14 Regression] " pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: xry111 at gcc dot gnu.org @ 2023-09-11  8:43 UTC (permalink / raw)
  To: gcc-bugs

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

Xi Ruoyao <xry111 at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2023-09-11

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

* [Bug tree-optimization/111365] [13/14 Regression] Wrong code at -O3 since r13-1268-g8c99e307b20
  2023-09-11  7:25 [Bug c/111365] New: Wrong code at -O3 since r13-1268-g8c99e307b20 shaohua.li at inf dot ethz.ch
                   ` (3 preceding siblings ...)
  2023-09-11  8:43 ` xry111 at gcc dot gnu.org
@ 2023-09-17 20:08 ` pinskia at gcc dot gnu.org
  2023-09-17 20:08 ` pinskia at gcc dot gnu.org
  2023-10-20 13:58 ` rguenth at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-17 20:08 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |14.0
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=111445,
                   |                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=111383
            Summary|Wrong code at -O3 since     |[13/14 Regression] Wrong
                   |r13-1268-g8c99e307b20       |code at -O3 since
                   |                            |r13-1268-g8c99e307b20

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

* [Bug tree-optimization/111365] [13/14 Regression] Wrong code at -O3 since r13-1268-g8c99e307b20
  2023-09-11  7:25 [Bug c/111365] New: Wrong code at -O3 since r13-1268-g8c99e307b20 shaohua.li at inf dot ethz.ch
                   ` (4 preceding siblings ...)
  2023-09-17 20:08 ` [Bug tree-optimization/111365] [13/14 Regression] " pinskia at gcc dot gnu.org
@ 2023-09-17 20:08 ` pinskia at gcc dot gnu.org
  2023-10-20 13:58 ` rguenth at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-17 20:08 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|14.0                        |13.3

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

* [Bug tree-optimization/111365] [13/14 Regression] Wrong code at -O3 since r13-1268-g8c99e307b20
  2023-09-11  7:25 [Bug c/111365] New: Wrong code at -O3 since r13-1268-g8c99e307b20 shaohua.li at inf dot ethz.ch
                   ` (5 preceding siblings ...)
  2023-09-17 20:08 ` pinskia at gcc dot gnu.org
@ 2023-10-20 13:58 ` rguenth at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-10-20 13:58 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
Fixed by r14-4789-g44e7e4498c3cdc.

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

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

end of thread, other threads:[~2023-10-20 13:58 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-11  7:25 [Bug c/111365] New: Wrong code at -O3 since r13-1268-g8c99e307b20 shaohua.li at inf dot ethz.ch
2023-09-11  8:21 ` [Bug tree-optimization/111365] " xry111 at gcc dot gnu.org
2023-09-11  8:37 ` xry111 at gcc dot gnu.org
2023-09-11  8:41 ` xry111 at gcc dot gnu.org
2023-09-11  8:43 ` xry111 at gcc dot gnu.org
2023-09-17 20:08 ` [Bug tree-optimization/111365] [13/14 Regression] " pinskia at gcc dot gnu.org
2023-09-17 20:08 ` pinskia at gcc dot gnu.org
2023-10-20 13:58 ` 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).