aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gnat.dg
diff options
context:
space:
mode:
authorEric Botcazou <ebotcazou@adacore.com>2022-11-04 11:23:12 +0100
committerEric Botcazou <ebotcazou@adacore.com>2022-11-04 15:14:50 +0100
commit0bdf10bdf1b2c9f31e7e764dec4d56ea6044f943 (patch)
tree25b2ac3b00d05621a82a46657a3dd214fe1d3a72 /gcc/testsuite/gnat.dg
parent3e2bdf2460a34a2389dee813a2ba8ecf976f2ec9 (diff)
downloadgcc-0bdf10bdf1b2c9f31e7e764dec4d56ea6044f943.zip
gcc-0bdf10bdf1b2c9f31e7e764dec4d56ea6044f943.tar.gz
gcc-0bdf10bdf1b2c9f31e7e764dec4d56ea6044f943.tar.bz2
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.
Diffstat (limited to 'gcc/testsuite/gnat.dg')
-rw-r--r--gcc/testsuite/gnat.dg/opt99.adb15
-rw-r--r--gcc/testsuite/gnat.dg/opt99_pkg1.adb10
-rw-r--r--gcc/testsuite/gnat.dg/opt99_pkg1.ads19
-rw-r--r--gcc/testsuite/gnat.dg/opt99_pkg2.ads13
4 files changed, 57 insertions, 0 deletions
diff --git a/gcc/testsuite/gnat.dg/opt99.adb b/gcc/testsuite/gnat.dg/opt99.adb
new file mode 100644
index 0000000..8805d47
--- /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 0000000..476b09c
--- /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 0000000..3e26561
--- /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 0000000..09aaff1
--- /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;