Sorry, Joseph. I am resending this because I forgot to include some fixes in the test directives in the patch before sending (I had tested it with these changes). As the only change is the dejagnu part and the rest was ok, I will wait a bit and then submit it if I do not hear any objections.
Bootstrapped and regression tested on x86_64. c: Fix ICE on invalid code involving bit fields [PR121217] Under some error condition we can end up with NULL_TREEs for the type of bitfields, which can cause an ICE when testing for type compatibility. Add the missing check. PR c/121217 gcc/c/ChangeLog: * c-typeck.cc (tagged_types_tu_compatible_p): Add check. gcc/testsuite/ChangeLog: * gcc.dg/pr121271.c: New test. diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc index ed6e56e7279..e586ac02325 100644 --- a/gcc/c/c-typeck.cc +++ b/gcc/c/c-typeck.cc @@ -1970,6 +1970,9 @@ tagged_types_tu_compatible_p (const_tree t1, const_tree t2, ft2 = DECL_BIT_FIELD_TYPE (s2); } + if (!ft1 || !ft2) + return false; + if (TREE_CODE (ft1) == ERROR_MARK || TREE_CODE (ft2) == ERROR_MARK) return false; diff --git a/gcc/testsuite/gcc.dg/pr121217.c b/gcc/testsuite/gcc.dg/pr121217.c new file mode 100644 index 00000000000..313f1e317a6 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr121217.c @@ -0,0 +1,19 @@ +/* { dg-do compile } */ +/* { dg-options "-std=gnu17" } */ + +typedef union{ + char *nordic_ref; + unsigned long long int bit_number; + enum PinMode mode : 2; /* { dg-warning "narrower" } */ + /* { dg-error "field 'mode'" "" { target *-*-* } .-1 } */ + unsigned char value; + } s; typedef struct{ + union{ + char *nordic_ref; + unsigned long long int bit_number; + enum PinMode mode : 2; /* { dg-warning "narrower" } */ + /* { dg-error "field 'mode'" "" { target *-*-* } .-1 } */ + unsigned char value; + } s; +} /* { dg-error "expected identifier" } */ +