From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1285) id 7E6033858C2B; Fri, 4 Nov 2022 14:19:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7E6033858C2B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1667571552; bh=Wp7cbngtWZ3oexG0lrPVtb2JTEOE4XJweSs6QtNf/a0=; h=From:To:Subject:Date:From; b=AIOGe2Qp4itGHaFkOpJxxcYWFRMt39aKYFpGZgEzVfG032FbGW04vN3049zvfNrqh QxaSxIPGt+0cZZdZKp9FjToXfmXbAlod+Gt7AzQWV/kDznN39uv9tCAdFEBL2032X+ 9woe+lxGCCAM9WsbvpKynoiJo/t0WRduMnQie+jo= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Eric Botcazou To: gcc-cvs@gcc.gnu.org Subject: [gcc r11-10364] Fix recent thinko in operand_equal_p X-Act-Checkin: gcc X-Git-Author: Eric Botcazou X-Git-Refname: refs/heads/releases/gcc-11 X-Git-Oldrev: 57da0797a73f32c879bca77e121a4f55fcc57ce1 X-Git-Newrev: 9a0e5b68a3604e62dc41c23587a5762bf3816470 Message-Id: <20221104141912.7E6033858C2B@sourceware.org> Date: Fri, 4 Nov 2022 14:19:12 +0000 (GMT) List-Id: https://gcc.gnu.org/g:9a0e5b68a3604e62dc41c23587a5762bf3816470 commit r11-10364-g9a0e5b68a3604e62dc41c23587a5762bf3816470 Author: Eric Botcazou Date: Fri Nov 4 11:23:12 2022 +0100 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.c (operand_compare::operand_equal_p) : Do not take into account operand 2. (operand_compare::hash_operand) : 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. Diff: --- gcc/fold-const.c | 18 ++++-------------- gcc/testsuite/gnat.dg/opt99.adb | 15 +++++++++++++++ gcc/testsuite/gnat.dg/opt99_pkg1.adb | 10 ++++++++++ gcc/testsuite/gnat.dg/opt99_pkg1.ads | 19 +++++++++++++++++++ gcc/testsuite/gnat.dg/opt99_pkg2.ads | 13 +++++++++++++ 5 files changed, 61 insertions(+), 14 deletions(-) diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 901255a18d6..5b4053df520 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -3331,9 +3331,6 @@ operand_compare::operand_equal_p (const_tree arg0, const_tree arg1, if (compare_address && (flags & OEP_ADDRESS_OF_SAME_FIELD) == 0) { - if (TREE_OPERAND (arg0, 2) - || TREE_OPERAND (arg1, 2)) - return OP_SAME_WITH_NULL (2); tree field0 = TREE_OPERAND (arg0, 1); tree field1 = TREE_OPERAND (arg1, 1); @@ -3844,17 +3841,10 @@ operand_compare::hash_operand (const_tree t, inchash::hash &hstate, if (sflags & OEP_ADDRESS_OF) { hash_operand (TREE_OPERAND (t, 0), hstate, flags); - if (TREE_OPERAND (t, 2)) - hash_operand (TREE_OPERAND (t, 2), hstate, - flags & ~OEP_ADDRESS_OF); - else - { - tree field = TREE_OPERAND (t, 1); - hash_operand (DECL_FIELD_OFFSET (field), - hstate, flags & ~OEP_ADDRESS_OF); - hash_operand (DECL_FIELD_BIT_OFFSET (field), - hstate, flags & ~OEP_ADDRESS_OF); - } + hash_operand (DECL_FIELD_OFFSET (TREE_OPERAND (t, 1)), + hstate, flags & ~OEP_ADDRESS_OF); + hash_operand (DECL_FIELD_BIT_OFFSET (TREE_OPERAND (t, 1)), + hstate, flags & ~OEP_ADDRESS_OF); return; } break; diff --git a/gcc/testsuite/gnat.dg/opt99.adb b/gcc/testsuite/gnat.dg/opt99.adb new file mode 100644 index 00000000000..8805d47c122 --- /dev/null +++ b/gcc/testsuite/gnat.dg/opt99.adb @@ -0,0 +1,15 @@ +-- { dg-do run } +-- { dg-options "-O" } + +with Opt99_Pkg1; use Opt99_Pkg1; + +procedure Opt99 is + C : constant My_Character := (D => True, C => ' '); + D : Derived; + +begin + Set (D, C, C); + if not D.C2.D then + raise Program_Error; + end if; +end; diff --git a/gcc/testsuite/gnat.dg/opt99_pkg1.adb b/gcc/testsuite/gnat.dg/opt99_pkg1.adb new file mode 100644 index 00000000000..476b09c9524 --- /dev/null +++ b/gcc/testsuite/gnat.dg/opt99_pkg1.adb @@ -0,0 +1,10 @@ +package body Opt99_Pkg1 is + + procedure Set (D: in out Derived; C1, C2 : My_Character) is + begin + D.I := 0; + D.C1 := C1; + D.C2 := C2; + end; + +end Opt99_Pkg1; diff --git a/gcc/testsuite/gnat.dg/opt99_pkg1.ads b/gcc/testsuite/gnat.dg/opt99_pkg1.ads new file mode 100644 index 00000000000..3e265616d14 --- /dev/null +++ b/gcc/testsuite/gnat.dg/opt99_pkg1.ads @@ -0,0 +1,19 @@ +with Opt99_Pkg2; + +package Opt99_Pkg1 is + + type My_Character (D : Boolean := False) is record + case D is + when False => null; + when True => C : Character; + end case; + end record; + + type Derived is new Opt99_Pkg2.Root with record + I : Integer; + C1, C2 : My_Character; + end record; + + procedure Set (D: in out Derived; C1, C2 : My_Character); + +end Opt99_Pkg1; diff --git a/gcc/testsuite/gnat.dg/opt99_pkg2.ads b/gcc/testsuite/gnat.dg/opt99_pkg2.ads new file mode 100644 index 00000000000..09aaff14e01 --- /dev/null +++ b/gcc/testsuite/gnat.dg/opt99_pkg2.ads @@ -0,0 +1,13 @@ +package Opt99_Pkg2 is + + function Get_Max return Positive is (4); + + C : constant Positive := Get_Max; + + type Arr is array (1 .. C) of Integer; + + type Root is tagged record + Data : Arr; + end record; + +end Opt99_Pkg2;