]> gcc.gnu.org Git - gcc.git/commit
fold-const: Handle C++ dependent COMPONENT_REFs in operand_equal_p [PR105035]
authorJakub Jelinek <jakub@redhat.com>
Thu, 24 Mar 2022 11:23:51 +0000 (12:23 +0100)
committerJakub Jelinek <jakub@redhat.com>
Tue, 29 Mar 2022 05:52:32 +0000 (07:52 +0200)
commitcb2520db3a35758affc7b90b8fefe927fc972516
tree4acccdb4da84eaf22497fec4c73ddd55a3d13e05
parent51b5fa6b4257850c99094f2cf7ece949b00a7826
fold-const: Handle C++ dependent COMPONENT_REFs in operand_equal_p [PR105035]

As mentioned in the PR, operand_equal_p already contains some hacks so that
it can be called already on pre-instantiation C++ trees from templates,
but the recent change to compare DECL_FIELD_OFFSET in the COMPONENT_REF
case broke this.  Many such COMPONENT_REFs are already punted on earlier
because they have NULL TREE_TYPE, but in this case the code knows what
type they have but still uses an IDENTIFIER_NODE as second operand
of COMPONENT_REF (I think SCOPE_REF is something that could be used too).

The following patch looks at those DECL_FIELD_*OFFSET fields only if
both field[01] args are FIELD_DECLs and otherwise keeps it to the
earlier OP_SAME (1) check that guards this whole block.

2022-03-24  Jakub Jelinek  <jakub@redhat.com>

PR c++/105035
* fold-const.c (operand_equal_p) <case COMPONENT_REF>: If either
field0 or field1 is not a FIELD_DECL, return false.

* g++.dg/warn/Wduplicated-cond2.C: New test.

(cherry picked from commit 8698ff67cdff4364c8adad2921ed532359a155ec)
gcc/fold-const.c
gcc/testsuite/g++.dg/warn/Wduplicated-cond2.C [new file with mode: 0644]
This page took 0.064287 seconds and 6 git commands to generate.