From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id B334F385480F; Fri, 18 Jun 2021 09:21:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B334F385480F MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jakub Jelinek To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-1640] stor-layout: Don't create DECL_BIT_FIELD_REPRESENTATIVE for QUAL_UNION_TYPE [PR101062] X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/master X-Git-Oldrev: ba71587184b28fd04eb56ac6ac8e7ad5bdab8ac5 X-Git-Newrev: 76e990fd211cbb20bf74ce074eb8b2d7b096d3b7 Message-Id: <20210618092156.B334F385480F@sourceware.org> Date: Fri, 18 Jun 2021 09:21:56 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Jun 2021 09:21:56 -0000 https://gcc.gnu.org/g:76e990fd211cbb20bf74ce074eb8b2d7b096d3b7 commit r12-1640-g76e990fd211cbb20bf74ce074eb8b2d7b096d3b7 Author: Jakub Jelinek Date: Fri Jun 18 11:20:40 2021 +0200 stor-layout: Don't create DECL_BIT_FIELD_REPRESENTATIVE for QUAL_UNION_TYPE [PR101062] > The following patch does create them, but treats all such bitfields as if > they were in a structure where the particular bitfield is the only field. While the patch passed bootstrap/regtest on the trunk, when trying to backport it to 11 branch the bootstrap failed with atree.ads:3844:34: size for "Node_Record" too small errors. Turns out the error is not about size being too small, but actually about size being non-constant, and comes from: /* In a FIELD_DECL of a RECORD_TYPE, this is a pointer to the storage representative FIELD_DECL. */ #define DECL_BIT_FIELD_REPRESENTATIVE(NODE) \ (FIELD_DECL_CHECK (NODE)->field_decl.qualifier) /* For a FIELD_DECL in a QUAL_UNION_TYPE, records the expression, which if nonzero, indicates that the field occupies the type. */ #define DECL_QUALIFIER(NODE) (FIELD_DECL_CHECK (NODE)->field_decl.qualifier) so by setting up DECL_BIT_FIELD_REPRESENTATIVE in QUAL_UNION_TYPE we actually set or modify DECL_QUALIFIER and then construct size as COND_EXPRs with those bit field representatives (e.g. with array type) as conditions which doesn't fold into constant. The following patch fixes it by not creating DECL_BIT_FIELD_REPRESENTATIVEs for QUAL_UNION_TYPE as there is nowhere to store them, Shall we change tree.h to document that DECL_BIT_FIELD_REPRESENTATIVE is valid also on UNION_TYPE? I see: tree-ssa-alias.c- if (TREE_CODE (type1) == RECORD_TYPE tree-ssa-alias.c: && DECL_BIT_FIELD_REPRESENTATIVE (field1)) tree-ssa-alias.c: field1 = DECL_BIT_FIELD_REPRESENTATIVE (field1); tree-ssa-alias.c- if (TREE_CODE (type2) == RECORD_TYPE tree-ssa-alias.c: && DECL_BIT_FIELD_REPRESENTATIVE (field2)) tree-ssa-alias.c: field2 = DECL_BIT_FIELD_REPRESENTATIVE (field2); Shall we change that to || == UNION_TYPE or do we assume all fields are overlapping in a UNION_TYPE already? At other spots (asan, ubsan, expr.c) it is unclear what will happen if they see a QUAL_UNION_TYPE with a DECL_QUALIFIER (or does the Ada FE lower that somehow)? 2021-06-18 Jakub Jelinek PR middle-end/101062 * stor-layout.c (finish_bitfield_layout): Don't add bitfield representatives in QUAL_UNION_TYPE. Diff: --- gcc/stor-layout.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/gcc/stor-layout.c b/gcc/stor-layout.c index 4e3a41b34e9..9f850c3951e 100644 --- a/gcc/stor-layout.c +++ b/gcc/stor-layout.c @@ -2172,6 +2172,9 @@ finish_bitfield_layout (tree t) tree field, prev; tree repr = NULL_TREE; + if (TREE_CODE (t) == QUAL_UNION_TYPE) + return; + for (prev = NULL_TREE, field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field)) {