Skip to content

Commit 194ab79

Browse files
committed
c: Avoid ICE with _BitInt(N) : 0 bitfield [PR113740]
finish_struct already made sure not to call build_bitint_type for signed _BitInt(2) : 1; or signed _BitInt(2) : 0; bitfields (but instead build a zero precision integral type, we remove it later), this patch makes sure we do it also for unsigned _BitInt(1) : 0; because of the build_bitint_type assertion that precision is >= (unsigned ? 1 : 2). 2024-02-05 Jakub Jelinek <[email protected]> PR c/113740 * c-decl.cc (finish_struct): Only use build_bitint_type if bit-field has width larger or equal to minimum _BitInt precision. * gcc.dg/bitint-85.c: New test.
1 parent 8ca585e commit 194ab79

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

gcc/c/c-decl.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9555,7 +9555,7 @@ finish_struct (location_t loc, tree t, tree fieldlist, tree attributes,
95559555
if (width != TYPE_PRECISION (type))
95569556
{
95579557
if (TREE_CODE (type) == BITINT_TYPE
9558-
&& (width > 1 || TYPE_UNSIGNED (type)))
9558+
&& width >= (TYPE_UNSIGNED (type) ? 1 : 2))
95599559
TREE_TYPE (field)
95609560
= build_bitint_type (width, TYPE_UNSIGNED (type));
95619561
else

gcc/testsuite/gcc.dg/bitint-85.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/* PR c/113740 */
2+
/* { dg-do compile { target bitint } } */
3+
/* { dg-options "-std=c23" } */
4+
5+
struct S { unsigned _BitInt(32) : 0; };

0 commit comments

Comments
 (0)