public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [COMMITTED] ada: Simplify expansion of packed array assignments
@ 2023-11-07  9:19 Marc Poulhiès
  0 siblings, 0 replies; only message in thread
From: Marc Poulhiès @ 2023-11-07  9:19 UTC (permalink / raw)
  To: gcc-patches; +Cc: Piotr Trojanek

From: Piotr Trojanek <trojanek@adacore.com>

When expanding assignment to a packed array object, e.g. a formal
parameter with mode OUT that might have unconstrained type, we took the
component type and component size from the constrained actual subtype.
It is simpler to take these properties from the nominal type of the
assigned object.

Semantics is unaffected, because constraining the array doesn't change
the type or size of the array components.

gcc/ada/

	* exp_pakd.adb (Expand_Bit_Packed_Element_Set): Change Ctyp and Csiz
	from variables to constants and compute them using the nominal type
	of the assigned array object.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/exp_pakd.adb | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/gcc/ada/exp_pakd.adb b/gcc/ada/exp_pakd.adb
index 68f0db3d56d..2b92c467187 100644
--- a/gcc/ada/exp_pakd.adb
+++ b/gcc/ada/exp_pakd.adb
@@ -1059,10 +1059,12 @@ package body Exp_Pakd is
       Obj   : Node_Id;
       Atyp  : Entity_Id;
       PAT   : Entity_Id;
-      Ctyp  : Entity_Id;
-      Csiz  : Int;
       Cmask : Uint;
 
+      Arr_Typ : constant Entity_Id := Etype (Prefix (Lhs));
+      Ctyp    : constant Entity_Id := Component_Type (Arr_Typ);
+      Csiz    : constant Int := UI_To_Int (Component_Size (Arr_Typ));
+
       Shift : Node_Id;
       --  The expression for the shift value that is required
 
@@ -1111,8 +1113,6 @@ package body Exp_Pakd is
       Convert_To_Actual_Subtype (Obj);
       Atyp := Etype (Obj);
       PAT  := Packed_Array_Impl_Type (Atyp);
-      Ctyp := Component_Type (Atyp);
-      Csiz := UI_To_Int (Component_Size (Atyp));
 
       --  We remove side effects, in case the rhs modifies the lhs, because we
       --  are about to transform the rhs into an expression that first READS
-- 
2.42.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-11-07  9:19 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-07  9:19 [COMMITTED] ada: Simplify expansion of packed array assignments Marc Poulhiès

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).