[Bug tree-optimization/101080] New: wrong code with "-O3"

suochenyao at 163 dot com gcc-bugzilla@gcc.gnu.org
Tue Jun 15 14:16:20 GMT 2021


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

            Bug ID: 101080
           Summary: wrong code with "-O3"
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: suochenyao at 163 dot com
  Target Milestone: ---

*******************************************************************************
OS and Platform:
CentOS Linux release 7.8.2003 (Core), x86_64 GNU/Linux
*******************************************************************************
Program:
struct a {
  unsigned b : 3;
} const c;
char d;
int e;
long f;
void g(const struct a h) {
  for (; d != 20; d = d + 4) {
    int i = h.b;
    e = h.b;
    f = h.b || 0;
  }
}
int main() { g(c); }
*******************************************************************************
gcc version:
$ gcc -v
Using built-in specs.
COLLECT_GCC=/data/bin/gcc-dev/bin/gcc
COLLECT_LTO_WRAPPER=/data/bin/gcc-dev/libexec/gcc/x86_64-pc-linux-gnu/12.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../configure --prefix=/data/bin/gcc-dev --disable-multilib
--enable-languages=c,c++
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 12.0.0 20210614 (experimental) (GCC)


git version: f9598d89a9f5a327ecdfa6f6978a0cfbe4447111
*******************************************************************************
Command Lines:
$ gcc a.c -o a1.out
$ gcc -O3 -Wall -Wextra -fno-strict-aliasing -fwrapv  a.c -o a2.out
a.c: In function ‘g’:
a.c:9:9: warning: unused variable ‘i’ [-Wunused-variable]
    9 |     int i = h.b;
      |         ^
$ ./a1.out
$ ./a2.out
Segmentation fault (core dumped)


More information about the Gcc-bugs mailing list