public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/111256] New: Wrong code at -O2/3/s since r10-1615-g75efe9cb1f8
@ 2023-08-31  8:42 shaohua.li at inf dot ethz.ch
  2023-08-31  9:12 ` [Bug c/111256] " xry111 at gcc dot gnu.org
  2023-08-31  9:23 ` xry111 at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: shaohua.li at inf dot ethz.ch @ 2023-08-31  8:42 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 111256
           Summary: Wrong code at -O2/3/s since r10-1615-g75efe9cb1f8
           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: rguenth at gcc dot gnu.org
  Target Milestone: ---

gcc at -O2/3/s produces the wrong code.

Bisected to r10-1615-g75efe9cb1f8

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

$ cat a.c
int printf(const char *, ...);
int a, d, e, g;
long b, h;
long i() {
  b++;
  return b;
}
int l(int m[], int p[]) {
  if (d)
    for (; e; e++) {
      m[4] = m[0] = m[1] ^ m[2] ^ m[5];
      m[7] = m[3] ^ m[6];
      m += 4;
    }
  m[6] = m[0] ^ 1;
  m[7] = m[1] ^ m[2] ^ m[7];
  m[9] = m[3] ^ m[8];
  return 1;
}
int fn3() {
  int j[] = {0, 7, 0, 0, 5, 0, 0, 8, 0, 0};
  int k[17];
  int c = l(j, k);
  return c;
}
int main() {
  for (; h <= 3; h = fn3() + h) {
    long n[2];
    for (; i() < 2;)
      n[g] = 508;
    for (; (int)n[0] < 2;) {
      char o[] = {3, 4, 6, 3, 0, 0, 5, 6, 6, 1, 7, 0, 0, 0, 0, 0};
      char *f = o;
      for (; *f; ++f)
        ;
    }
  }
  printf("%X\n", a);
}
$
$ gcc -O0 a.c && ./a.out
0
$ gcc -O2 a.c
% ./a.out
(Timeout)

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

* [Bug c/111256] Wrong code at -O2/3/s since r10-1615-g75efe9cb1f8
  2023-08-31  8:42 [Bug c/111256] New: Wrong code at -O2/3/s since r10-1615-g75efe9cb1f8 shaohua.li at inf dot ethz.ch
@ 2023-08-31  9:12 ` xry111 at gcc dot gnu.org
  2023-08-31  9:23 ` xry111 at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: xry111 at gcc dot gnu.org @ 2023-08-31  9:12 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |xry111 at gcc dot gnu.org
         Resolution|---                         |INVALID
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #1 from Xi Ruoyao <xry111 at gcc dot gnu.org> ---
In the 2nd iteration of "for (; h <= 3; h = fn3() + h)" the code uses
uninitialized value:

$ clang t.c -O0 -fsanitize=memory -g
$ ./a.out 
==76055==WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 0x56392dea5370 in main /home/xry111/t.c:31:5
    #1 0x7f9671e27f59 in __libc_start_call_main
/home/xry111/sources/lfs/glibc-2.38/csu/../sysdeps/nptl/libc_start_call_main.h:58:16
    #2 0x7f9671e28024 in __libc_start_main@GLIBC_2.2.5
/home/xry111/sources/lfs/glibc-2.38/csu/../csu/libc-start.c:360:3
    #3 0x56392de0f2d0 in _start
/home/xry111/sources/lfs/glibc-2.38/csu/../sysdeps/x86_64/start.S:115

SUMMARY: MemorySanitizer: use-of-uninitialized-value /home/xry111/t.c:31:5 in
main
Exiting

Thus invalid.

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

* [Bug c/111256] Wrong code at -O2/3/s since r10-1615-g75efe9cb1f8
  2023-08-31  8:42 [Bug c/111256] New: Wrong code at -O2/3/s since r10-1615-g75efe9cb1f8 shaohua.li at inf dot ethz.ch
  2023-08-31  9:12 ` [Bug c/111256] " xry111 at gcc dot gnu.org
@ 2023-08-31  9:23 ` xry111 at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: xry111 at gcc dot gnu.org @ 2023-08-31  9:23 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Xi Ruoyao <xry111 at gcc dot gnu.org> ---
If you don't have Clang, you can also reproduce the timeout with
-ftrivial-auto-var-init=zero or -ftrivial-auto-var-init=pattern (in GCC 12 or
later).

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

end of thread, other threads:[~2023-08-31  9:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-31  8:42 [Bug c/111256] New: Wrong code at -O2/3/s since r10-1615-g75efe9cb1f8 shaohua.li at inf dot ethz.ch
2023-08-31  9:12 ` [Bug c/111256] " xry111 at gcc dot gnu.org
2023-08-31  9:23 ` xry111 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).