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

            Bug ID: 102920
           Summary: [12 Regression] 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: vsevolod.livinskij at frtk dot ru
  Target Milestone: ---

https://godbolt.org/z/qn3dsxsW8

Reproducer:
#include <stdio.h>

unsigned short a = 42;
unsigned short b = 1;
long long int c = 1;
unsigned char var_120;
unsigned char var_123;

void test(unsigned short a, unsigned short b, long long int c)
__attribute__((noipa));

void test(unsigned short a, unsigned short b, long long c) {
    for (char i = 0; i < (char)c; i += 5)
        if (!b)
            var_120 = a;
        else
            var_123 = a;
}

int main() {
    test(a, b, c);
    printf("%hhu\n", var_123);
    //if (var_123 != 42)
    //    __builtin_abort();
}

Error:
>$ g++ -O3 small.cpp && ./a.out
0
>$ g++ -O2 small.cpp && ./a.out
42

GCC version:
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/testing/gcc/bin_master/libexec/gcc/x86_64-pc-linux-gnu/12.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /testing/gcc/gcc_src_master/configure --enable-multilib
--prefix=/testing/gcc/bin_master --disable-bootstrap
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 12.0.0 20211023 (experimental) (GCC) 
root@abe71269b867:/testing/result/S_1635079215/reduce# cat
/testing/gcc/gcc_rev.txt 
git://gcc.gnu.org/git/gcc.git:master
e3725624ec0735996a18e1a90317e230bef899ac

Reply via email to