aboutsummaryrefslogtreecommitdiff
path: root/gcc/fold-const.c
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2020-12-04 18:00:54 +0100
committerJakub Jelinek <jakub@redhat.com>2020-12-04 18:02:10 +0100
commit33be07be9e46f15b9556521050356c47460651ee (patch)
treedef7d97da300eb743fc2831c4f82c51be7db2947 /gcc/fold-const.c
parent5a26d4a204c8a462a7e0a1a86bb2f25ecd470aad (diff)
downloadgcc-33be07be9e46f15b9556521050356c47460651ee.zip
gcc-33be07be9e46f15b9556521050356c47460651ee.tar.gz
gcc-33be07be9e46f15b9556521050356c47460651ee.tar.bz2
fold-const: Don't use build_constructor for non-aggregate types in native_encode_initializer [PR93121]
The following testcase is rejected, because when trying to encode a zeroing CONSTRUCTOR, the code was using build_constructor to build initializers for the elements but when recursing the function handles CONSTRUCTOR only for aggregate types. The following patch fixes that by using build_zero_cst instead for non-aggregates. Another option would be add handling CONSTRUCTOR for non-aggregates in native_encode_initializer. Or we can do both, I guess the middle-end generally doesn't like CONSTRUCTORs for scalar variables, but am not 100% sure if the FE doesn't produce those sometimes. 2020-12-04 Jakub Jelinek <jakub@redhat.com> PR libstdc++/93121 * fold-const.c (native_encode_initializer): Use build_zero_cst instead of build_constructor. * g++.dg/cpp2a/bit-cast6.C: New test.
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r--gcc/fold-const.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index e77d74e..1241b13 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -8104,11 +8104,12 @@ native_encode_initializer (tree init, unsigned char *ptr, int len,
{
if (valueinit == -1)
{
- tree zero = build_constructor (TREE_TYPE (type), NULL);
+ tree zero = build_zero_cst (TREE_TYPE (type));
r = native_encode_initializer (zero, ptr + curpos,
fieldsize, 0,
mask + curpos);
- ggc_free (zero);
+ if (TREE_CODE (zero) == CONSTRUCTOR)
+ ggc_free (zero);
if (!r)
return 0;
valueinit = curpos;
@@ -8255,8 +8256,9 @@ native_encode_initializer (tree init, unsigned char *ptr, int len,
{
cnt--;
field = fld;
- val = build_constructor (TREE_TYPE (fld), NULL);
- to_free = val;
+ val = build_zero_cst (TREE_TYPE (fld));
+ if (TREE_CODE (val) == CONSTRUCTOR)
+ to_free = val;
}
}