gimple-fold: Fix up __builtin_clear_padding on classes with virtual inheritence ...
authorJakub Jelinek <jakub@redhat.com>
Tue, 27 Jul 2021 07:59:37 +0000 (09:59 +0200)
committerJakub Jelinek <jakub@redhat.com>
Tue, 27 Jul 2021 07:59:37 +0000 (09:59 +0200)
commita21bd3cebd6f54af70a37c18b8fbeae933fb6515
tree84262a34a51b1b3a9fc51ac12d9d6239bb737598
parent5485e820cd0554886af282265198c7433c64c7b9
gimple-fold: Fix up __builtin_clear_padding on classes with virtual inheritence [PR101586]

For the following testcase, B is 16-byte type, containing 8-byte
virtual pointer and 1-byte A member, and C contains two FIELD_DECLs,
one with B type and size of just 8-byte and then a field with type
A and 1-byte size.
The __builtin_clear_padding code was upset about the B typed FIELD_DECL
containing FIELD_DECLs beyond the field size and triggered
assertion failure.
This patch makes it ignore all FIELD_DECLs that are (fully) beyond the sz
passed from the caller (except for the flexible array member
diagnostics that is kept).

2021-07-27  Jakub Jelinek  <jakub@redhat.com>

PR middle-end/101586
* gimple-fold.c (clear_padding_type): Ignore FIELD_DECLs with byte
positions above or equal to sz except for diagnostics of flexible
array members.

* g++.dg/torture/builtin-clear-padding-4.C: New test.
gcc/gimple-fold.c
gcc/testsuite/g++.dg/torture/builtin-clear-padding-4.C [new file with mode: 0644]