Hi! 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. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2025-12-06 Jakub Jelinek <[email protected]> PR c/123018 * c-decl.cc (finish_struct): Diagnose bit-fields with vector type. * gcc.dg/pr123018.c: New test. --- gcc/c/c-decl.cc.jj 2025-11-24 09:02:57.000000000 +0100 +++ gcc/c/c-decl.cc 2025-12-05 12:08:16.758425836 +0100 @@ -9774,6 +9774,13 @@ finish_struct (location_t loc, tree t, t 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 --- gcc/testsuite/gcc.dg/pr123018.c.jj 2025-12-05 12:13:39.681771389 +0100 +++ gcc/testsuite/gcc.dg/pr123018.c 2025-12-05 12:14:13.889172407 +0100 @@ -0,0 +1,17 @@ +/* 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; +}; Jakub
