public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/110475] New: [14 Regression] Wrong code at -O2/3/s on x86_64-pc-linux-gnu
@ 2023-06-29  6:36 jwzeng at nuaa dot edu.cn
  2023-06-29  7:29 ` [Bug tree-optimization/110475] " pinskia at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: jwzeng at nuaa dot edu.cn @ 2023-06-29  6:36 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 110475
           Summary: [14 Regression] Wrong code at -O2/3/s on
                    x86_64-pc-linux-gnu
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jwzeng at nuaa dot edu.cn
  Target Milestone: ---

Link to the Compiler Explorer: https://godbolt.org/z/qTn1MErqh

The following code snippet:

#include <stdio.h>
unsigned long long int res = 0;
unsigned int a = 4042837206U;
int b = 1558001202;
#define min(a, b) ((a) < (b) ? (a) : (b))

int main() {
    res = (unsigned long long int) min(1, b ? a : 1558001202);
    printf("%llu\n", res);
    return 0;
}

> $ /usr/gcc-trunk/bin/gcc -O0 bug.c; ./a.out
> 1
> $ /usr/gcc-trunk/bin/gcc -O1 bug.c; ./a.out
> 1
> $ /usr/gcc-trunk/bin/gcc -O2 bug.c; ./a.out
> 4042837207
> $ /usr/gcc-trunk/bin/gcc -O3 bug.c; ./a.out
> 4042837207
> $ /usr/gcc-trunk/bin/gcc -Os bug.c; ./a.out
> 4042837207

When compiled with -O2/3/s, it prints the wrong result 4042837207 instead of 1.
Earlier GCCs do not have this bug.

The following statement is in the code snippet above:
> res = (unsigned long long int) min(1, b ? a : 1558001202);
When the last number 1558001202 of this statement is changed to 0 or 1, it will
also output the wrong result 4042837207 under the optimization of -O1. Changing
to other numbers that are not 0 or 1 will not make this program output wrong
results at -O1.

> $ /usr/gcc-trunk/bin/gcc --version

Using built-in specs.
COLLECT_GCC=/home/compilers/gcc/gcc-trunk/bin/gcc
COLLECT_LTO_WRAPPER=/home/compilers/gcc/gcc-trunk/bin/../libexec/gcc/x86_64-pc-linux-gnu/14.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../gcc-trunk-source/gcc/configure
--enable-languages=c,c++,fortran --enable-checking=release
--enable-valgrind-annotations --disable-werror --disable-libstdcxx-pch
--enable-libgomp --enable-lto --enable-gold --with-plugin-ld=gold
--prefix=/usr/local/gcc-trunk
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 14.0.0 20230619 (experimental) [master r14-1917-gf8e0270272] (GCC)

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

end of thread, other threads:[~2023-06-29 15:42 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-29  6:36 [Bug tree-optimization/110475] New: [14 Regression] Wrong code at -O2/3/s on x86_64-pc-linux-gnu jwzeng at nuaa dot edu.cn
2023-06-29  7:29 ` [Bug tree-optimization/110475] " pinskia at gcc dot gnu.org
2023-06-29  7:33 ` rguenth at gcc dot gnu.org
2023-06-29 15:42 ` 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).