public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/103222] New: [12 Regression] wrong code at -O2 and above on x86_64-linux-gnu
@ 2021-11-13  8:26 haoxintu at gmail dot com
  2021-11-13 11:07 ` [Bug tree-optimization/103222] " hubicka at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: haoxintu at gmail dot com @ 2021-11-13  8:26 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 103222
           Summary: [12 Regression] wrong code at -O2 and above on
                    x86_64-linux-gnu
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: haoxintu at gmail dot com
  Target Milestone: ---

Hi all.

$cat small.c
#include <stdint.h>
#include <stdio.h>
int16_t a;
static uint32_t *b ;
static uint8_t func_2();
static int32_t func_1() {
  int16_t a = 1;
  func_2(0, a, a);
  return 0;
}
uint8_t func_2(uint32_t p1, uint32_t p2, uint32_t p3) {
  int p = 0;
  for (15;; a++) {
    for (0;;) {
      if (p2)
        break;
      b = &p2;
      return p2;
    }
     p3 = (p2 = p3, p);
  }
  return 0;
}

int main() {
  func_1();
  printf("%d\n", a);
  return 0;
}

$gcc -O1 small.c ; ./a.out
2

$gcc -O2 small.c ; ./a.out
1

$gcc -O3 small.c ; ./a.out
1

$gcc -Os small.c ; ./a.out
1

$gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/home/haoxin/haoxin-data/compilers/gcc/build/libexec/gcc/x86_64-pc-linux-gnu/12.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with:../configure
--prefix=/home/haoxin/haoxin-data/compilers/gcc/build/ --enable-bootstrap
--enable-checking=release --enable-languages=c,c++ --enable-multilib :
(reconfigured) ../configure
--prefix=/home/haoxin/haoxin-data/compilers/gcc/build/ --enable-bootstrap
--enable-checking=release --enable-multilib --enable-languages=c,c++,lto
--no-create --no-recursion
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 12.0.0 20211113 (experimental) (GCC)


Note that this issue only happens in the current trunk version (12.0) of GCC.

Can also check in Godbolt: https://godbolt.org/z/rz7b9WxvT


Thanks,
Haoxin

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

end of thread, other threads:[~2021-11-19 12:22 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-13  8:26 [Bug tree-optimization/103222] New: [12 Regression] wrong code at -O2 and above on x86_64-linux-gnu haoxintu at gmail dot com
2021-11-13 11:07 ` [Bug tree-optimization/103222] " hubicka at gcc dot gnu.org
2021-11-13 11:45 ` aldyh at gcc dot gnu.org
2021-11-13 11:46 ` aldyh at gcc dot gnu.org
2021-11-13 13:41 ` cvs-commit at gcc dot gnu.org
2021-11-13 13:44 ` aldyh at gcc dot gnu.org
2021-11-13 14:15 ` haoxintu at gmail dot com
2021-11-19 12:22 ` 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).