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

            Bug ID: 126257
           Summary: [16/17 Regression] wrong code at -O2/3 with _BitInt(2)
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: xxs_chy at outlook dot com
  Target Milestone: ---

Reproducer: https://godbolt.org/z/59bcMqdP3
Testcase:
#include <stdint.h>
#include <stdio.h>
_BitInt(2) g5;
int64_t g14, __chk, g22;
int main()
{
    int32_t ov0;
    _BitInt(2) v2;
    _Bool c3;
    int64_t v6 = g14;
lbl_br3:
    ov0 = v6;
    if (ov0 != 4) v2 = -1;
    v2 = v2 + v2;
    g5 = v2;
    c3 = g22 - 4;
    if (!c3) goto lbl_br3;
    __chk = g5;
    printf("checksum=0x%016llx\n", (unsigned long long)__chk);
}

This case outputs checksum=0x0000000000000000 with -O2 and
checksum=0xfffffffffffffffe with -O0.

And UBSan seems to report a false positive, as the reported line is actually a
legal addition of -1 and -1:
example.c:14:8: runtime error: signed integer overflow: -1 * -2 cannot be
represented in type '_BitInt(2)'

Reply via email to