public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/112305] New: [13/14 Regression] Wrong code at -O1/2/3/s on x86_64-pc-linux-gnu
@ 2023-10-31  6:51 jwzeng at nuaa dot edu.cn
  2023-10-31  7:00 ` [Bug middle-end/112305] " pinskia at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: jwzeng at nuaa dot edu.cn @ 2023-10-31  6:51 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 112305
           Summary: [13/14 Regression] Wrong code at -O1/2/3/s 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 -O1/2/3/s, and it produces the wrong
code. The correct output result should be -1560359471, but -486617677 was
output under -O1/2/3/s.
I found this bug was introduced starting from gcc-13.1

Compiler explorer: https://godbolt.org/z/s7K9z5166

```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 -O0; ./test.c
-1560359471
$ gcc-tk test.c -O1; ./test.c
-486617677
$ gcc-tk test.c -O2; ./test.c
-486617677
$ gcc-tk test.c -O3; ./test.c
-486617677
$ gcc-tk test.c -Os; ./test.c
-486617677
$ ccomp test.c -O1; ./a.out
-1560359471
$
$ gcc-tk --version
gcc (GCC) 14.0.0 20231028 (experimental) [master r14-4987-g7f974c5fd4]
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] 9+ messages in thread

end of thread, other threads:[~2024-05-21  9:18 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-31  6:51 [Bug middle-end/112305] New: [13/14 Regression] Wrong code at -O1/2/3/s on x86_64-pc-linux-gnu jwzeng at nuaa dot edu.cn
2023-10-31  7:00 ` [Bug middle-end/112305] " pinskia at gcc dot gnu.org
2023-10-31  7:02 ` pinskia at gcc dot gnu.org
2023-10-31  7:07 ` [Bug middle-end/112305] [11/12/13/14 " pinskia at gcc dot gnu.org
2023-10-31  7:08 ` pinskia at gcc dot gnu.org
2023-10-31  9:10 ` rguenth at gcc dot gnu.org
2023-10-31 12:10 ` cvs-commit at gcc dot gnu.org
2023-10-31 12:18 ` [Bug middle-end/112305] [11/12/13 " rguenth at gcc dot gnu.org
2024-05-21  9:18 ` 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).