diff --git a/gcc/gimple-lower-bitint.cc b/gcc/gimple-lower-bitint.cc index 3869a164992..8993a6136e7 100644 --- a/gcc/gimple-lower-bitint.cc +++ b/gcc/gimple-lower-bitint.cc @@ -6606,8 +6606,12 @@ gimple_lower_bitint (void) = build_array_type_nelts (large_huge.m_limb_type, nelts); tree ptype = build_pointer_type (TREE_TYPE (v1)); - tree off = fold_convert (ptype, - TYPE_SIZE_UNIT (TREE_TYPE (c))); + tree off; + if (c) + off = fold_convert (ptype, + TYPE_SIZE_UNIT (TREE_TYPE (c))); + else + off = build_zero_cst (ptype); tree vd = build2 (MEM_REF, vtype, build_fold_addr_expr (v1), off); g = gimple_build_assign (vd, build_zero_cst (vtype)); diff --git a/gcc/testsuite/gcc.dg/bitint-62.c b/gcc/testsuite/gcc.dg/bitint-62.c new file mode 100644 index 00000000000..2c3139c9560 --- /dev/null +++ b/gcc/testsuite/gcc.dg/bitint-62.c @@ -0,0 +1,32 @@ +/* PR tree-optimization/113120 */ +/* { dg-do compile { target bitint } } */ +/* { dg-options "-std=c23 -O2" } */ + +_BitInt(8) a; +_BitInt(55) b; + +#if __BITINT_MAXWIDTH__ >= 401 +static __attribute__((noinline, noclone)) void +foo (unsigned _BitInt(1) c, _BitInt(401) d) +{ + c /= d << b; + a = c; +} + +void +bar (void) +{ + foo (1, 4); +} +#endif + +#if __BITINT_MAXWIDTH__ >= 6928 +_BitInt(6928) +baz (int x, _BitInt(6928) y) +{ + if (x) + return y; + else + return 0; +} +#endif