aboutsummaryrefslogtreecommitdiff
path: root/gcc/fold-const.c
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2020-12-09 09:34:51 +0100
committerJakub Jelinek <jakub@redhat.com>2020-12-09 09:34:51 +0100
commit4164e58bfd5d57e7399f91c7c27ae6ccebc7dcb0 (patch)
treee9f70fb13606ba8e2fead253f67b67e68dbd85d0 /gcc/fold-const.c
parentc3a63fb3854392af65a191154e3586e7f5a1066e (diff)
downloadgcc-4164e58bfd5d57e7399f91c7c27ae6ccebc7dcb0.zip
gcc-4164e58bfd5d57e7399f91c7c27ae6ccebc7dcb0.tar.gz
gcc-4164e58bfd5d57e7399f91c7c27ae6ccebc7dcb0.tar.bz2
fold-const: Fix up native_encode_initializer missing field handling [PR98193]
When native_encode_initializer is called with non-NULL mask (i.e. ATM bit_cast only), it checks if the current index in the CONSTRUCTOR (if any) is the next initializable FIELD_DECL, and if not, decrements cnt and performs the iteration with that FIELD_DECL as field and val of zero (so that it computes mask properly). As the testcase shows, I forgot to set pos to the byte position of the field though (like it is done for e.g. index referenced FIELD_DECLs in the constructor. 2020-12-09 Jakub Jelinek <jakub@redhat.com> PR c++/98193 * fold-const.c (native_encode_initializer): Set pos to field's byte position if iterating over a field with missing initializer. * g++.dg/cpp2a/bit-cast7.C: New test.
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r--gcc/fold-const.c1
1 files changed, 1 insertions, 0 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 1241b13..81467f1 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -8256,6 +8256,7 @@ native_encode_initializer (tree init, unsigned char *ptr, int len,
{
cnt--;
field = fld;
+ pos = int_byte_position (field);
val = build_zero_cst (TREE_TYPE (fld));
if (TREE_CODE (val) == CONSTRUCTOR)
to_free = val;