From 46003600f4f9faf5fcfaa748d98bbb25f5d0652d Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Wed, 5 Sep 2018 10:04:58 +0000 Subject: PR c++/87137] GCC-8 Fix https://gcc.gnu.org/ml/gcc-patches/2018-08/msg01966.html PR c++/87137 * stor-layout.c (place_field): Scan forwards to check last bitfield when ms_bitfield_placement is in effect. gcc/testsuite/ * g++.dg/abi/pr87137.C: New. git-svn-id: https://gcc.gnu.org/svn/gcc/trunk@264119 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/stor-layout.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'gcc/stor-layout.c') diff --git a/gcc/stor-layout.c b/gcc/stor-layout.c index 088f3606a0d..58a3aa369fa 100644 --- a/gcc/stor-layout.c +++ b/gcc/stor-layout.c @@ -1686,14 +1686,21 @@ place_field (record_layout_info rli, tree field) { rli->bitpos = size_binop (PLUS_EXPR, rli->bitpos, DECL_SIZE (field)); - /* If we ended a bitfield before the full length of the type then - pad the struct out to the full length of the last type. */ - if ((DECL_CHAIN (field) == NULL - || TREE_CODE (DECL_CHAIN (field)) != FIELD_DECL) - && DECL_BIT_FIELD_TYPE (field) + /* If FIELD is the last field and doesn't end at the full length + of the type then pad the struct out to the full length of the + last type. */ + if (DECL_BIT_FIELD_TYPE (field) && !integer_zerop (DECL_SIZE (field))) - rli->bitpos = size_binop (PLUS_EXPR, rli->bitpos, - bitsize_int (rli->remaining_in_alignment)); + { + /* We have to scan, because non-field DECLS are also here. */ + tree probe = field; + while ((probe = DECL_CHAIN (probe))) + if (TREE_CODE (probe) == FIELD_DECL) + break; + if (!probe) + rli->bitpos = size_binop (PLUS_EXPR, rli->bitpos, + bitsize_int (rli->remaining_in_alignment)); + } normalize_rli (rli); } -- cgit v1.2.3