stor-layout: Avoid DECL_BIT_FIELD_REPRESENTATIVE with NULL TREE_TYPE [PR101172]
authorJakub Jelinek <jakub@redhat.com>
Thu, 24 Jun 2021 10:22:14 +0000 (12:22 +0200)
committerJakub Jelinek <jakub@redhat.com>
Thu, 24 Jun 2021 10:22:14 +0000 (12:22 +0200)
commit65371066d8967560e3508af4a804e0ddb90acee7
treec26de24e5ec65d7fcdbcf6ca720a3bab9e0c9ae7
parenta1c1b7a888ade6f21bc7c7f05a2cbff290273fcc
stor-layout: Avoid DECL_BIT_FIELD_REPRESENTATIVE with NULL TREE_TYPE [PR101172]

finish_bitfield_representative has an early out if the field after a
bitfield has error_mark_node type, but that early out leads to TREE_TYPE
of the DECL_BIT_FIELD_REPRESENTATIVE being NULL, which breaks assumptions
on code that uses the DECL_BIT_FIELD_REPRESENTATIVE during error-recovery.

The following patch instead sets TREE_TYPE of the representative to
error_mark_node, something the users can deal with better.  At this point
the representative can be set as DECL_BIT_FIELD_REPRESENTATIVE for multiple
bitfields, so making sure that we clear the DECL_BIT_FIELD_REPRESENTATIVE
instead would be harder (but doable, e.g. with the error_mark_node TREE_TYPE
set by this patch set some flag in the caller and if the flag is there, walk
all the fields once again and clear all DECL_BIT_FIELD_REPRESENTATIVE that
have error_mark_node TREE_TYPE).

2021-06-24  Jakub Jelinek  <jakub@redhat.com>

PR middle-end/101172
* stor-layout.c (finish_bitfield_representative): If nextf has
error_mark_node type, set repr type to error_mark_node too.

* gcc.dg/pr101172.c: New test.
gcc/stor-layout.c
gcc/testsuite/gcc.dg/pr101172.c [new file with mode: 0644]