public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/111290] New: [11/12/13/14 Regression] Wrong code at -O0 on x86_64-pc-linux-gnu
@ 2023-09-05  6:20 jwzeng at nuaa dot edu.cn
  2023-09-05  6:45 ` [Bug middle-end/111290] " pinskia at gcc dot gnu.org
  2023-09-05  6:49 ` pinskia at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: jwzeng at nuaa dot edu.cn @ 2023-09-05  6:20 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 111290
           Summary: [11/12/13/14 Regression] Wrong code at -O0 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: ---

Compiler Explorer: https://godbolt.org/z/Ee3fMoqPr

The following code snippet, gcc at -O0 produces the wrong code. I tested it on
other versions of gcc and found that this bug was introduced starting from
`gcc-4.9.0`.

$ cat test.c
#include <stdint.h>
int printf(const char *, ...);
volatile uint16_t a = (unsigned short)27267;
volatile int32_t b = 191725925;
volatile int32_t c = 633417204;
volatile uint64_t d = 6049561019410052129ULL;
volatile int32_t e = 2024295172;
volatile int8_t res = (signed char)108;
int main()
{
    b = (c |= d / a) >= ((e %= 0x6B1D8456) > (res ^= c));
    printf("%d\n", res);
}
$
$ gcc-tk test.c; ./a.out
-104
$ gcc-4.9.0 test.c; ./a.out
-104
$ gcc-4.8.5 test.c; ./a.out
-112
$ clang-tk test.c; ./a.out
-112
$ ccomp test.c; ./a.out
-112
$
$ gcc-tk --version
gcc (GCC) 14.0.0 20230829 (experimental) [master r14-3534-gebffc840f5]
Copyright (C) 2023 Free Software Foundation, Inc.
$
$ gcc-4.9.0 --version
gcc (GCC) 4.9.0
Copyright (C) 2014 Free Software Foundation, Inc.
$
$ gcc-4.8.5 --version
gcc (GCC) 4.8.5
Copyright (C) 2015 Free Software Foundation, Inc.
$
$ clang-tk --version
Ubuntu clang version 18.0.0
(++20230821052626+634b2fd2cac2-1~exp1~20230821172748.738)
Target: x86_64-pc-linux-gnu
$
$ ccomp --version
The CompCert C verified compiler, version 3.12

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

* [Bug middle-end/111290] [11/12/13/14 Regression] Wrong code at -O0 on x86_64-pc-linux-gnu
  2023-09-05  6:20 [Bug middle-end/111290] New: [11/12/13/14 Regression] Wrong code at -O0 on x86_64-pc-linux-gnu jwzeng at nuaa dot edu.cn
@ 2023-09-05  6:45 ` pinskia at gcc dot gnu.org
  2023-09-05  6:49 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-05  6:45 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |INVALID
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
<source>: In function 'main':
<source>:12:12: warning: operation on 'c' may be undefined [-Wsequence-point]
   12 |     b = (c |= d / a) >= ((e %= 0x6B1D8456) > (res ^= c));
      |            ^~

Both answers are correct for C.

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

* [Bug middle-end/111290] [11/12/13/14 Regression] Wrong code at -O0 on x86_64-pc-linux-gnu
  2023-09-05  6:20 [Bug middle-end/111290] New: [11/12/13/14 Regression] Wrong code at -O0 on x86_64-pc-linux-gnu jwzeng at nuaa dot edu.cn
  2023-09-05  6:45 ` [Bug middle-end/111290] " pinskia at gcc dot gnu.org
@ 2023-09-05  6:49 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-05  6:49 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
```
int main()
{
        int t = c;
        c |= d / a;
    b = (c) >= ((e %= 0x6B1D8456) > (res ^= t));
    printf("%d\n", res);
}
```
gives -104
While:
```
int main()
{
        c |= d / a;
        int t = c;
    b = (c) >= ((e %= 0x6B1D8456) > (res ^= t));
    printf("%d\n", res);
}
```

Gives -112 
Both are valid way of representing the original code as there is no sequence
point between them.

Note C++11 makes this well defined.

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

end of thread, other threads:[~2023-09-05  6:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-05  6:20 [Bug middle-end/111290] New: [11/12/13/14 Regression] Wrong code at -O0 on x86_64-pc-linux-gnu jwzeng at nuaa dot edu.cn
2023-09-05  6:45 ` [Bug middle-end/111290] " pinskia at gcc dot gnu.org
2023-09-05  6:49 ` pinskia 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).