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

            Bug ID: 129091
           Summary: UBSan at every -O level: signed integer overflow
                    `(HOST_WIDE_INT_1 << thissize) - 1` with thissize ==
                    63 in store_split_bit_field (expmed.cc) for a _BitInt
                    bit-field store
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: haoxintu at gmail dot com
  Target Milestone: ---

Hi,

$cat repro.c

struct S {
  long long : 63;
  _BitInt(127) b : 64;
};
void f(struct S *p) { p->b = 0; }

With GCC itself built with `-fsanitize=address,undefined` (bootstrap-ubsan /
bootstrap-asan style build of trunk):


$ gcc -O0 -c repro.c
gcc/expmed.cc:1523:13: runtime error: signed integer overflow:
-9223372036854775808 - 1 cannot be represented in type 'long int'
    #0 store_split_bit_field gcc/expmed.cc:1523
    #1 store_fixed_bit_field gcc/expmed.cc:1291
    #2 store_integral_bit_field gcc/expmed.cc:1160
    #3 store_bit_field_1 gcc/expmed.cc:914
    #4 store_bit_field(...)
    #5 store_field gcc/expr.cc:8476
    #6 expand_assignment(tree_node*, tree_node*, bool) gcc/expr.cc:6381


## Checked versions
  - gcc trunk r17 (113f18c2309, 2026-10-17) built with
-fsanitize=address,undefined: the error above at -O0, -O1, -O2, -O3, -Os
  - The expression is unchanged in the current trunk (gcc/expmed.cc lines 1503
and 1525 at origin/master, 2026-11-27)

Thanks.

Reply via email to