]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Fix weird error in Ada.Numerics.Discrete_Random with Component_Alignment
authorEric Botcazou <ebotcazou@adacore.com>
Fri, 18 Oct 2024 07:28:17 +0000 (09:28 +0200)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Tue, 12 Nov 2024 13:00:45 +0000 (14:00 +0100)
The problem arises when an instance of Ada.Numerics.Discrete_Random is
covered by a pragma Component_Alignment with a non-default alignment.

gcc/ada/ChangeLog:

* exp_ch5.adb (Expand_Assign_Array): Make Act_Rhs a constant and
do not recompute it, as well as R_Type, when there is a change of
representation.  Move comment about the RHS from here to...
(Expand_N_Assignment_Statement): ...here.

gcc/ada/exp_ch5.adb

index 8cad734628a6889b571dcf18c6e08ead2d0320d3..b8840450026dc83bbb71556328410e665cdfae0c 100644 (file)
@@ -340,7 +340,7 @@ package body Exp_Ch5 is
       Lhs : constant Node_Id := Name (N);
 
       Act_Lhs : constant Node_Id := Get_Referenced_Object (Lhs);
-      Act_Rhs : Node_Id          := Get_Referenced_Object (Rhs);
+      Act_Rhs : constant Node_Id := Get_Referenced_Object (Rhs);
 
       L_Type : constant Entity_Id :=
                  Underlying_Type (Get_Actual_Subtype (Act_Lhs));
@@ -515,14 +515,9 @@ package body Exp_Ch5 is
          Set_Backwards_OK (N, False);
       end if;
 
-      --  We certainly must use a loop for change of representation and also
-      --  we use the operand of the conversion on the right-hand side as the
-      --  effective right-hand side (the component types must match in this
-      --  situation).
+      --  We certainly must use a loop for change of representation
 
       if Crep then
-         Act_Rhs := Get_Referenced_Object (Rhs);
-         R_Type  := Get_Actual_Subtype (Act_Rhs);
          Loop_Required := True;
 
       --  We require a loop if either side is possibly bit aligned
@@ -3283,6 +3278,10 @@ package body Exp_Ch5 is
       --  Array types
 
       elsif Is_Array_Type (Typ) then
+         --  We use the operand of a conversion on the right-hand side as the
+         --  effective right-hand side (the component types must match in this
+         --  situation).
+
          declare
             Actual_Rhs : Node_Id := Rhs;