diff mbox series

[Ada] Refine use of access types in unnesting

Message ID 20200706113855.GA135491@adacore.com
State New
Headers show
Series [Ada] Refine use of access types in unnesting | expand

Commit Message

Pierre-Marie de Rodat July 6, 2020, 11:38 a.m. UTC
When we pass an unconstrained value in an activation record, we pass it
an access type instead of an address so that we can get the bounds in
the nested subprogram.  However, the current code does this only when
the uplevel reference is a parameter and uses 'Access.  There are cases,
as introduced in the fix for C760A02, involving a renaming, where an
object is an unconstrained array type, but not a parameter.  Moreover,
we should use 'Unchecked_Access to avoid error messages in that case.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

	* exp_unst.adb (Needs_Fat_Pointer): Don't check for formal.
	(Unnest_Subprogram): Use 'Unchecked_Access instead of 'Access
	when populating activation record.
diff mbox series

Patch

diff --git a/gcc/ada/exp_unst.adb b/gcc/ada/exp_unst.adb
--- a/gcc/ada/exp_unst.adb
+++ b/gcc/ada/exp_unst.adb
@@ -251,18 +251,14 @@  package body Exp_Unst is
    -----------------------
 
    function Needs_Fat_Pointer (E : Entity_Id) return Boolean is
-      Typ : Entity_Id;
-   begin
-      if Is_Formal (E) then
-         Typ := Etype (E);
-         if Is_Private_Type (Typ) and then Present (Full_View (Typ)) then
-            Typ := Full_View (Typ);
-         end if;
+      Typ : Entity_Id := Etype (E);
 
-         return Is_Array_Type (Typ) and then not Is_Constrained (Typ);
-      else
-         return False;
+   begin
+      if Is_Private_Type (Typ) and then Present (Full_View (Typ)) then
+         Typ := Full_View (Typ);
       end if;
+
+      return Is_Array_Type (Typ) and then not Is_Constrained (Typ);
    end Needs_Fat_Pointer;
 
    ----------------
@@ -2084,7 +2080,7 @@  package body Exp_Unst is
                                  --  or else 'Access for unconstrained array
 
                                  if Needs_Fat_Pointer (Ent) then
-                                    Attr := Name_Access;
+                                    Attr := Name_Unchecked_Access;
                                  else
                                     Attr := Name_Address;
                                  end if;