fold-const: Don't use build_constructor for non-aggregate types in native_encode_init...
authorJakub Jelinek <jakub@redhat.com>
Fri, 4 Dec 2020 17:00:54 +0000 (18:00 +0100)
committerJakub Jelinek <jakub@redhat.com>
Fri, 4 Dec 2020 17:02:10 +0000 (18:02 +0100)
commit33be07be9e46f15b9556521050356c47460651ee
treedef7d97da300eb743fc2831c4f82c51be7db2947
parent5a26d4a204c8a462a7e0a1a86bb2f25ecd470aad
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.
gcc/fold-const.c
gcc/testsuite/g++.dg/cpp2a/bit-cast6.C [new file with mode: 0644]