aboutsummaryrefslogtreecommitdiff
path: root/gcc/stor-layout.c
diff options
context:
space:
mode:
authorRichard Biener <rguenther@suse.de>2016-12-16 09:40:03 +0000
committerRichard Biener <rguenth@gcc.gnu.org>2016-12-16 09:40:03 +0000
commitb7fc43d7c747d190e197ca89cfce4f1d9def7c7e (patch)
treee7a4831ca7b46e08d1f5bc38c1d4f221aa7cfbbe /gcc/stor-layout.c
parentc4d5c5e6ac73cac2b89d039eff9874ff80742589 (diff)
downloadgcc-b7fc43d7c747d190e197ca89cfce4f1d9def7c7e.zip
gcc-b7fc43d7c747d190e197ca89cfce4f1d9def7c7e.tar.gz
gcc-b7fc43d7c747d190e197ca89cfce4f1d9def7c7e.tar.bz2
re PR c++/71694 (store-data race with bitfields and tail-padding in C++)
2016-12-16 Richard Biener <rguenther@suse.de> PR c++/71694 * langhooks-def.h (lhd_unit_size_without_reusable_padding): Declare. (LANG_HOOKS_UNIT_SIZE_WITHOUT_REUSABLE_PADDING): Define. (LANG_HOOKS_FOR_TYPES_INITIALIZER): Adjust. * langhooks.h (struct lang_hooks_for_types): Add unit_size_without_reusable_padding. * langhooks.c (lhd_unit_size_without_reusable_padding): New. * stor-layout.c (finish_bitfield_representative): Use unit_size_without_reusable_padding langhook to decide on the last representatives size. cp/ * cp-objcp-common.h (cp_unit_size_without_reusable_padding): Declare. (LANG_HOOKS_UNIT_SIZE_WITHOUT_REUSABLE_PADDING): Define. * cp-objcp-common.c (cp_unit_size_without_reusable_padding): New. * g++.dg/pr71694.C: New testcase. From-SVN: r243738
Diffstat (limited to 'gcc/stor-layout.c')
-rw-r--r--gcc/stor-layout.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/gcc/stor-layout.c b/gcc/stor-layout.c
index 5a4bcf1..0aa3861 100644
--- a/gcc/stor-layout.c
+++ b/gcc/stor-layout.c
@@ -1864,13 +1864,14 @@ finish_bitfield_representative (tree repr, tree field)
}
else
{
- /* ??? If you consider that tail-padding of this struct might be
- re-used when deriving from it we cannot really do the following
- and thus need to set maxsize to bitsize? Also we cannot
- generally rely on maxsize to fold to an integer constant, so
- use bitsize as fallback for this case. */
- tree maxsize = size_diffop (TYPE_SIZE_UNIT (DECL_CONTEXT (field)),
- DECL_FIELD_OFFSET (repr));
+ /* Note that if the C++ FE sets up tail-padding to be re-used it
+ creates a as-base variant of the type with TYPE_SIZE adjusted
+ accordingly. So it is safe to include tail-padding here. */
+ tree aggsize = lang_hooks.types.unit_size_without_reusable_padding
+ (DECL_CONTEXT (field));
+ tree maxsize = size_diffop (aggsize, DECL_FIELD_OFFSET (repr));
+ /* We cannot generally rely on maxsize to fold to an integer constant,
+ so use bitsize as fallback for this case. */
if (tree_fits_uhwi_p (maxsize))
maxbitsize = (tree_to_uhwi (maxsize) * BITS_PER_UNIT
- tree_to_uhwi (DECL_FIELD_BIT_OFFSET (repr)));