public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "jwzeng at nuaa dot edu.cn" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug middle-end/112305] New: [13/14 Regression] Wrong code at -O1/2/3/s on x86_64-pc-linux-gnu
Date: Tue, 31 Oct 2023 06:51:04 +0000	[thread overview]
Message-ID: <bug-112305-4@http.gcc.gnu.org/bugzilla/> (raw)

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
```

             reply	other threads:[~2023-10-31  6:51 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-31  6:51 jwzeng at nuaa dot edu.cn [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-112305-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).