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

            Bug ID: 128726
           Summary: [16/17 Regression] a live _BitInt(129) value is
                    overwritten by an unused one from an inlined call
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: shimizu2486 at gmail dot com
  Target Milestone: ---

Live reproducer: https://godbolt.org/z/94seYYd1a

$ cat t1.c
#include <stdio.h>
int b, c, g, o;
typedef struct {
  unsigned _BitInt(129) x;
} S;
_BitInt(7) t;
S m;
int f(int p) {
  unsigned char l = p;
  for (; c;)
    l = 0;
  if (g <= p - (unsigned _BitInt(129))l)
    l = 0;
  t = (_BitInt(7))g / p;
  if ((t & 3) == 3)
    l = 0;
  return l;
}
int main(void) {
  S v = m;
  int r;
  o = __builtin_mul_overflow(v.x, b, &r);
  f(384);
  printf("%llu\n", (unsigned long long)v.x);
}

v is a copy of m, which is zero, and nothing changes it, so the program prints
0.

$ gcc -O0 t1.c -o t1 && ./t1
0                    (correct)
$ gcc -O2 t1.c -o t1 && ./t1
256                  (wrong)

  x86-64 trunk (372c32f911fa)   wrong
  x86-64 16.2.0                 wrong
  x86-64 15.3.0                 correct
  x86-64 14.4.0                 correct

-O2 is wrong; -O0, -O1, -O3, -Os and -Og are correct.
-fno-tree-coalesce-vars, -fno-inline, -fno-tree-vrp, -fno-tree-fre or
-fno-thread-jumps gives the correct value.
arm-linux-gnueabihf -O2 is wrong the same way.

256 is p - (unsigned _BitInt(129))l in f (384 - 128), the operand of its
comparison, which is never stored. With unsigned _BitInt(128) or unsigned
__int128 in place of unsigned _BitInt(129) the program compiles correct, and
every wider type I tried (_BitInt(130), _BitInt(192), _BitInt(256),
_BitInt(575)) is wrong, so I assume it needs a _BitInt wider than 128 bits, the
kind bitintlower splits into limbs.

Reply via email to