]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c: Avoid ICE with _BitInt(N) : 0 bitfield [PR113740]
authorJakub Jelinek <jakub@redhat.com>
Mon, 5 Feb 2024 17:53:59 +0000 (18:53 +0100)
committerJakub Jelinek <jakub@redhat.com>
Mon, 5 Feb 2024 17:53:59 +0000 (18:53 +0100)
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  <jakub@redhat.com>

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.

gcc/c/c-decl.cc
gcc/testsuite/gcc.dg/bitint-85.c [new file with mode: 0644]

index 934e557dc3bb4a4d32cb59c55ea7379b5a0bdb8e..fe20bc21c926f9353c774a1be5aa64fb94018c64 100644 (file)
@@ -9555,7 +9555,7 @@ finish_struct (location_t loc, tree t, tree fieldlist, tree attributes,
          if (width != TYPE_PRECISION (type))
            {
              if (TREE_CODE (type) == BITINT_TYPE
-                 && (width > 1 || TYPE_UNSIGNED (type)))
+                 && width >= (TYPE_UNSIGNED (type) ? 1 : 2))
                TREE_TYPE (field)
                  = build_bitint_type (width, TYPE_UNSIGNED (type));
              else
diff --git a/gcc/testsuite/gcc.dg/bitint-85.c b/gcc/testsuite/gcc.dg/bitint-85.c
new file mode 100644 (file)
index 0000000..f2301cc
--- /dev/null
@@ -0,0 +1,5 @@
+/* PR c/113740 */
+/* { dg-do compile { target bitint } } */
+/* { dg-options "-std=c23" } */
+
+struct S { unsigned _BitInt(32) : 0; };