diff options
author | Jakub Jelinek <jakub@redhat.com> | 2024-04-04 10:47:52 +0200 |
---|---|---|
committer | Jakub Jelinek <jakub@redhat.com> | 2024-04-04 10:47:52 +0200 |
commit | 1baec8deb014b8a7da58879a407a4c00cdeb5a09 (patch) | |
tree | 48dd255854b36baf8285b26dfca482b1d7fbed85 /gcc/fold-const.cc | |
parent | 48530efdcccb154d3ed200246384edc162debc5d (diff) | |
download | gcc-1baec8deb014b8a7da58879a407a4c00cdeb5a09.zip gcc-1baec8deb014b8a7da58879a407a4c00cdeb5a09.tar.gz gcc-1baec8deb014b8a7da58879a407a4c00cdeb5a09.tar.bz2 |
fold-const: Handle NON_LVALUE_EXPR in native_encode_initializer [PR114537]
The following testcase is incorrectly rejected. The problem is that
for bit-fields native_encode_initializer expects the corresponding
CONSTRUCTOR elt value must be INTEGER_CST, but that isn't the case
here, it is wrapped into NON_LVALUE_EXPR by maybe_wrap_with_location.
We could STRIP_ANY_LOCATION_WRAPPER as well, but as all we are looking for
is INTEGER_CST inside, just looking through NON_LVALUE_EXPR seems easier.
2024-04-04 Jakub Jelinek <jakub@redhat.com>
PR c++/114537
* fold-const.cc (native_encode_initializer): Look through
NON_LVALUE_EXPR if val is INTEGER_CST.
* g++.dg/cpp2a/bit-cast16.C: New test.
Diffstat (limited to 'gcc/fold-const.cc')
-rw-r--r-- | gcc/fold-const.cc | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/gcc/fold-const.cc b/gcc/fold-const.cc index 8960e52..7b26896 100644 --- a/gcc/fold-const.cc +++ b/gcc/fold-const.cc @@ -8601,6 +8601,8 @@ native_encode_initializer (tree init, unsigned char *ptr, int len, if (BYTES_BIG_ENDIAN != WORDS_BIG_ENDIAN) return 0; + if (TREE_CODE (val) == NON_LVALUE_EXPR) + val = TREE_OPERAND (val, 0); if (TREE_CODE (val) != INTEGER_CST) return 0; |