public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/110129] New: Possible wrong-code on -O2 and above (affecting versions from GCC-10.1 onward)
@ 2023-06-05 15:48 haoxintu at gmail dot com
  2023-06-05 15:58 ` [Bug tree-optimization/110129] " pinskia at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: haoxintu at gmail dot com @ 2023-06-05 15:48 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 110129
           Summary: Possible wrong-code on -O2 and above (affecting
                    versions from GCC-10.1 onward)
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: haoxintu at gmail dot com
  Target Milestone: ---

Hi,

Please consider the following code, which makes GCC output different results on
-O0/1 and -O2/3/s. Note that all the GCC-10.1 (including) onwards versions
behave the same.

$cat test.c
#include <stdio.h>
int c = 0;
int ids = 0;
struct {
  int a;
} b;
void __attribute__((noinline)) marker_1() {
    printf(" b%db ", 1);
    ids++;
}
int d(int e) {
  b.a = 0;
  for (e = 0; e < 8; e++)
    for (c = 0; c < 9; c++)
      if (c){
        for (; e; )
            ;
      }
  return b.a;
}
int main() {
  int f[1] = {0};
  if (d(c), f)
    marker_1();
  printf("%d\n", ids);
}

$gcc-trunk -w -O1 test.c ;./a.out
(hang)
$gcc-trunk -w -O2 test.c ;./a.out
b1b 1

$gcc-10.1 -w -O1 test.c ;./a.out
(hang)
$gcc-10.1 -w -O2 test.c ;./a.out
b1b 1

$gcc-9.5 -w -O1 test.c ;./a.out
(hang)
$gcc-9.5 -w -O2 test.c ;./a.out
b1b 1


GCC version:
Using built-in specs.
COLLECT_GCC=/opt/compiler-explorer/gcc-snapshot/bin/g++
COLLECT_LTO_WRAPPER=/opt/compiler-explorer/gcc-trunk-20230605/bin/../libexec/gcc/x86_64-linux-gnu/14.0.0/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../gcc-trunk-20230605/configure
--prefix=/opt/compiler-explorer/gcc-build/staging
--enable-libstdcxx-backtrace=yes --build=x86_64-linux-gnu
--host=x86_64-linux-gnu --target=x86_64-linux-gnu --disable-bootstrap
--enable-multiarch --with-abi=m64 --with-multilib-list=m32,m64,mx32
--enable-multilib --enable-clocale=gnu
--enable-languages=c,c++,fortran,ada,objc,obj-c++,go,d,rust,m2 --enable-ld=yes
--enable-gold=yes --enable-libstdcxx-debug --enable-libstdcxx-time=yes
--enable-linker-build-id --enable-lto --enable-plugins --enable-threads=posix
--with-pkgversion=Compiler-Explorer-Build-gcc-b48890844d94092fdf6e9c941af4a47b9c0ce982-binutils-2.40
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 14.0.0 20230605 (experimental)
(Compiler-Explorer-Build-gcc-b48890844d94092fdf6e9c941af4a47b9c0ce982-binutils-2.40) 

Example in GodBolt: https://godbolt.org/z/3YhczK7oj


Thanks,
Haoxin

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

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

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-05 15:48 [Bug tree-optimization/110129] New: Possible wrong-code on -O2 and above (affecting versions from GCC-10.1 onward) haoxintu at gmail dot com
2023-06-05 15:58 ` [Bug tree-optimization/110129] " pinskia at gcc dot gnu.org
2023-06-05 16:24 ` haoxintu at gmail dot com
2023-06-05 23:04 ` pinskia at gcc dot gnu.org
2023-06-05 23:09 ` 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).