]> git.ipfire.org Git - thirdparty/gcc.git/commit
Fix recent thinko in operand_equal_p
authorEric Botcazou <ebotcazou@adacore.com>
Fri, 4 Nov 2022 10:23:12 +0000 (11:23 +0100)
committerEric Botcazou <ebotcazou@adacore.com>
Fri, 4 Nov 2022 14:16:22 +0000 (15:16 +0100)
commit33561e870dc48966e8c7ede46e95032279a15423
treea7a89531c065456e2de527cbc551bf449cba746f
parent14a92220a2f061328aae32ee6b5cdc7f62375902
Fix recent thinko in operand_equal_p

There is a thinko in a recent improvement made to operand_equal_p where
the code just looks at operand 2 of COMPONENT_REF, if it is present, to
compare addresses.  That's wrong because operand 2 contains the number of
DECL_OFFSET_ALIGN-bit-sized words so, when DECL_OFFSET_ALIGN > 8, not all
the  bytes are included and some of them are in DECL_FIELD_BIT_OFFSET, see
get_inner_reference for the model computation.

In other words, you would need to compare operand 2 and DECL_OFFSET_ALIGN
and DECL_FIELD_BIT_OFFSET in this situation, but I'm not sure this is worth
the hassle in practice so the fix just removes this alternate handling.

gcc/
* fold-const.cc (operand_compare::operand_equal_p) <COMPONENT_REF>:
Do not take into account operand 2.
(operand_compare::hash_operand) <COMPONENT_REF>: Likewise.

gcc/testsuite/
* gnat.dg/opt99.adb: New test.
* gnat.dg/opt99_pkg1.ads, gnat.dg/opt99_pkg1.adb: New helper.
* gnat.dg/opt99_pkg2.ads: Likewise.
gcc/fold-const.cc
gcc/testsuite/gnat.dg/opt99.adb [new file with mode: 0644]
gcc/testsuite/gnat.dg/opt99_pkg1.adb [new file with mode: 0644]
gcc/testsuite/gnat.dg/opt99_pkg1.ads [new file with mode: 0644]
gcc/testsuite/gnat.dg/opt99_pkg2.ads [new file with mode: 0644]