From: Eric Botcazou <ebotca...@adacore.com>

These are the usual problematic patterns in the expanded code.

gcc/ada/ChangeLog:

        * exp_ch9.adb (Build_Dispatching_Requeue): Take 'Tag of the
        concurrent object instead of doing an unchecked conversion.
        * exp_pakd.adb (Expand_Packed_Address_Reference): Perform address
        arithmetic using an operator of System.Storage_Elements.

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

---
 gcc/ada/exp_ch9.adb  |  6 ++++--
 gcc/ada/exp_pakd.adb | 31 +++++++++++++++++--------------
 2 files changed, 21 insertions(+), 16 deletions(-)

diff --git a/gcc/ada/exp_ch9.adb b/gcc/ada/exp_ch9.adb
index d75fd3a6825..dd59af970f5 100644
--- a/gcc/ada/exp_ch9.adb
+++ b/gcc/ada/exp_ch9.adb
@@ -9877,7 +9877,7 @@ package body Exp_Ch9 is
          --      (T        => To_Tag_Ptr (Obj'Address).all,
          --       Position =>
          --         Ada.Tags.Get_Offset_Index
-         --           (Ada.Tags.Tag (Concval),
+         --           (Concval._Tag,
          --            <interface dispatch table position of Ename>));
 
          --  Note that Obj'Address is recursively expanded into a call to
@@ -9898,7 +9898,9 @@ package body Exp_Ch9 is
                   Make_Function_Call (Loc,
                     Name => New_Occurrence_Of (RTE (RE_Get_Offset_Index), Loc),
                     Parameter_Associations => New_List (
-                      Unchecked_Convert_To (RTE (RE_Tag), Concval),
+                      Make_Attribute_Reference (Loc,
+                        Prefix         => Concval,
+                        Attribute_Name => Name_Tag),
                       Make_Integer_Literal (Loc,
                         DT_Position (Entity (Ename))))))));
 
diff --git a/gcc/ada/exp_pakd.adb b/gcc/ada/exp_pakd.adb
index 26ef065b529..f04016fa811 100644
--- a/gcc/ada/exp_pakd.adb
+++ b/gcc/ada/exp_pakd.adb
@@ -1526,21 +1526,24 @@ package body Exp_Pakd is
 
       Get_Base_And_Bit_Offset (Prefix (N), Base, Offset);
 
-      Rewrite (N,
-        Unchecked_Convert_To (RTE (RE_Address),
-          Make_Op_Add (Loc,
-            Left_Opnd =>
-              Unchecked_Convert_To (RTE (RE_Integer_Address),
-                Make_Attribute_Reference (Loc,
-                  Prefix         => Base,
-                  Attribute_Name => Name_Address)),
+      Offset := Unchecked_Convert_To (RTE (RE_Storage_Offset), Offset);
 
-            Right_Opnd =>
-              Unchecked_Convert_To (RTE (RE_Integer_Address),
-                Make_Op_Divide (Loc,
-                  Left_Opnd => Offset,
-                  Right_Opnd =>
-                    Make_Integer_Literal (Loc, System_Storage_Unit))))));
+      Rewrite (N,
+        Make_Function_Call (Loc,
+          Name =>
+            Make_Expanded_Name (Loc,
+              Chars         => Name_Op_Add,
+              Prefix        =>
+                New_Occurrence_Of (RTU_Entity (System_Storage_Elements), Loc),
+              Selector_Name => Make_Identifier (Loc, Name_Op_Add)),
+          Parameter_Associations => New_List (
+            Make_Attribute_Reference (Loc,
+              Prefix         => Base,
+              Attribute_Name => Name_Address),
+            Make_Op_Divide (Loc,
+              Left_Opnd  => Offset,
+              Right_Opnd =>
+                Make_Integer_Literal (Loc, System_Storage_Unit)))));
 
       Analyze_And_Resolve (N, RTE (RE_Address));
    end Expand_Packed_Address_Reference;
-- 
2.43.0

Reply via email to