public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/112344] New: [14 Regression] Wrong code at -O2 on x86_64-pc-linux-gnu
@ 2023-11-02  6:30 jwzeng at nuaa dot edu.cn
  2023-11-02  6:41 ` [Bug middle-end/112344] " pinskia at gcc dot gnu.org
                   ` (13 more replies)
  0 siblings, 14 replies; 15+ messages in thread
From: jwzeng at nuaa dot edu.cn @ 2023-11-02  6:30 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 112344
           Summary: [14 Regression] Wrong code at -O2 on
                    x86_64-pc-linux-gnu
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jwzeng at nuaa dot edu.cn
  Target Milestone: ---

I compiled the following code with gcc at -O2, and it produces the wrong code. 

The correct output result should be 13, but 73 was output under -O2. 

This bug seems to only exist on gcc-trunk. The gcc-tk used below is the
earliest version I can use that triggers this bug.

Compiler explorer: https://godbolt.org/z/8hq64asT5

```c
$ cat test.c
int printf(const char *, ...);
int a;
void b() {
  long c = 3;
  unsigned int d = 50253292;
  int e = 2147483648;
  for (; a < 5; a++)
    do {
      e += 4;
      d -= c;
    } while (e < 20);
  printf("%d\n", d);
}
int main() { b(); }
$
$ gcc-tk test.c -O2; ./test.c
73
$
$ gcc-tk test.c -O0; ./test.c
13
$ gcc-tk test.c -O1; ./test.c
13
$ gcc-tk test.c -O3; ./test.c
13
$ gcc-tk test.c -Os; ./test.c
13
$ ccomp test.c -O1; ./a.out
13
$
$ gcc-tk --version
gcc (GCC) 14.0.0 20230922 (experimental) [master r14-4213-gd35e12e1c0]
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$
$ ccomp --version
The CompCert C verified compiler, version 3.12
```

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

end of thread, other threads:[~2024-02-18 10:07 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-02  6:30 [Bug middle-end/112344] New: [14 Regression] Wrong code at -O2 on x86_64-pc-linux-gnu jwzeng at nuaa dot edu.cn
2023-11-02  6:41 ` [Bug middle-end/112344] " pinskia at gcc dot gnu.org
2023-11-02  6:42 ` pinskia at gcc dot gnu.org
2023-11-02  6:47 ` jwzeng at nuaa dot edu.cn
2023-11-02  6:49 ` pinskia at gcc dot gnu.org
2023-11-02 10:06 ` rguenth at gcc dot gnu.org
2023-11-21 19:22 ` jakub at gcc dot gnu.org
2023-11-21 19:23 ` jakub at gcc dot gnu.org
2023-11-22  7:43 ` rguenth at gcc dot gnu.org
2023-11-22  9:10 ` rguenth at gcc dot gnu.org
2023-11-22 10:06 ` rguenth at gcc dot gnu.org
2023-11-22 14:40 ` cvs-commit at gcc dot gnu.org
2023-11-22 14:41 ` rguenth at gcc dot gnu.org
2023-11-24  7:50 ` cvs-commit at gcc dot gnu.org
2024-02-18 10:07 ` cvs-commit 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).