public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "shaohua.li at inf dot ethz.ch" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/111472] New: Wrong code at -Os on x86_64-linux-gnu since
Date: Tue, 19 Sep 2023 07:38:32 +0000	[thread overview]
Message-ID: <bug-111472-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 111472
           Summary: Wrong code at -Os on x86_64-linux-gnu since
           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: amacleod at redhat dot com
  Target Milestone: ---

gcc at -Os produced the wrong code.

Bisected to r11-4563-gd0d8b5d836

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

With -fwrapv the issue goes away.

$ cat a.c
int printf(const char *, ...);
int a, b, e, f;
short c = -1, i;
char g;
int h[4][1] = {8, 5, 8, 5};
int main() {
  int *j = &e, *k = &f;
  unsigned short d = c;
  i = d >> b;
  *j = i;
  g = 0;
  for (; g <= 3; g++)
    *k = h[(unsigned char)(1 + e) + g][0];
  printf("%d\n", f);
}
$
$ gcc -O0 a.c && ./a.out
5
$ gcc -Os a.c && ./a.out
Segmentation fault
$
$ gcc -fsanitize=undefined a.c && ./a.out
5
$

             reply	other threads:[~2023-09-19  7:38 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-19  7:38 shaohua.li at inf dot ethz.ch [this message]
2023-09-19  7:45 ` [Bug tree-optimization/111472] Wrong code at -Os on x86_64-linux-gnu since r11-4563-gd0d8b5d836 xry111 at gcc dot gnu.org
2023-09-19  7:47 ` shaohua.li at inf dot ethz.ch
2023-09-19  7:48 ` [Bug tree-optimization/111472] [11/12/13/14 Regression] " xry111 at gcc dot gnu.org
2023-09-19  7:48 ` pinskia at gcc dot gnu.org
2023-11-06 20:31 ` amacleod at redhat dot com
2023-11-06 20:35 ` amacleod at redhat dot com
2023-11-06 20:37 ` pinskia at gcc dot gnu.org
2024-03-07 22:24 ` [Bug tree-optimization/111472] [11/12/13 " law at gcc dot gnu.org
2024-05-08 12:15 ` [Bug tree-optimization/111472] [11 " rguenth 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-111472-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).