The following testcase ICEs since checking has been added to TYPE_PRECISION
macro. check_bitfield_type_and_width is called when attributes haven't
been applied to the bit-field decl yet and so it still has INTEGER_TYPE
type, while at finish_struct time it already has VECTOR_TYPE.
The following patch just repeats the check_bitfield_type_and_width
in there.
Another option would be let handle_vector_size_attribute check for
bit-fields and error out there.
2025-12-09 Jakub Jelinek <jakub@redhat.com>
PR c/123018
* c-decl.cc (finish_struct): Diagnose bit-fields with vector type.
* gcc.dg/pr123018.c: New test.
unsigned HOST_WIDE_INT width
= tree_to_uhwi (DECL_INITIAL (field));
tree type = TREE_TYPE (field);
+ if (VECTOR_TYPE_P (type))
+ {
+ error_at (DECL_SOURCE_LOCATION (field),
+ "bit-field %qD has invalid type", field);
+ type = TREE_TYPE (type);
+ TREE_TYPE (field) = type;
+ }
if (width != TYPE_PRECISION (type))
{
if (TREE_CODE (type) == BITINT_TYPE
--- /dev/null
+/* PR c/123018 */
+/* { dg-do compile } */
+
+struct A {
+ int x : 8 __attribute__ ((vector_size (8))); /* { dg-error "bit-field 'x' has invalid type" } */
+};
+struct B {
+ float x : 8; /* { dg-error "bit-field 'x' has invalid type" } */
+};
+struct C {
+ int : 8 __attribute__ ((vector_size (8))); /* { dg-error "bit-field '\[^\n\r]*anonymous\[^\n\r]*' has invalid type" } */
+ int x;
+};
+struct D {
+ float : 8; /* { dg-error "bit-field '\[^\n\r]*anonymous\[^\n\r]*' has invalid type" } */
+ int x;
+};