diff mbox series

[Ada] Transient scope cleanup

Message ID 20210708135037.GA2466001@adacore.com
State New
Headers show
Series [Ada] Transient scope cleanup | expand

Commit Message

Pierre-Marie de Rodat July 8, 2021, 1:50 p.m. UTC
Misc cleanups found while working on transient scopes.

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

gcc/ada/

	* comperr.adb (Compiler_Abort): Call Sinput.Unlock, because if
	this is called late, then Source_Dump would crash otherwise.
	* debug.adb: Correct documentation of the -gnatd.9 switch.
	* exp_ch4.adb (Expand_Allocator_Expression): Add a comment.
	* exp_ch6.adb: Minor comment fixes.  Add assertion.
	* exp_ch6.ads (Is_Build_In_Place_Result_Type): Correct comment.
	* exp_ch7.adb, checks.ads: Minor comment fixes.
diff mbox series

Patch

diff --git a/gcc/ada/checks.ads b/gcc/ada/checks.ads
--- a/gcc/ada/checks.ads
+++ b/gcc/ada/checks.ads
@@ -851,7 +851,7 @@  package Checks is
    --    are not following the flow graph (more properly the flow of actual
    --    processing only corresponds to the flow graph for local assignments).
    --    For non-local variables, we preserve the current setting, i.e. a
-   --    validity check is performed when assigning to a knonwn valid global.
+   --    validity check is performed when assigning to a known valid global.
 
    --  Note: no validity checking is required if range checks are suppressed
    --  regardless of the setting of the validity checking mode.


diff --git a/gcc/ada/comperr.adb b/gcc/ada/comperr.adb
--- a/gcc/ada/comperr.adb
+++ b/gcc/ada/comperr.adb
@@ -404,6 +404,7 @@  package body Comperr is
          Set_Standard_Output;
 
          Tree_Dump;
+         Sinput.Unlock; -- so Source_Dump can modify it
          Source_Dump;
          raise Unrecoverable_Error;
       end if;


diff --git a/gcc/ada/debug.adb b/gcc/ada/debug.adb
--- a/gcc/ada/debug.adb
+++ b/gcc/ada/debug.adb
@@ -1101,7 +1101,7 @@  package body Debug is
    --       issues (e.g., assuming that a low bound of an array parameter
    --       of an unconstrained subtype belongs to the index subtype).
 
-   --  d.9  Enable build-in-place for function calls returning some nonlimited
+   --  d.9  Disable build-in-place for function calls returning nonlimited
    --       types.
 
    ------------------------------------------


diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb
--- a/gcc/ada/exp_ch4.adb
+++ b/gcc/ada/exp_ch4.adb
@@ -1166,6 +1166,9 @@  package body Exp_Ch4 is
          --  secondary stack). In that case, the object will be moved, so we do
          --  want to Adjust. However, if it's a nonlimited build-in-place
          --  function call, Adjust is not wanted.
+         --
+         --  Needs_Finalization (DesigT) can differ from Needs_Finalization (T)
+         --  if one of the two types is class-wide, and the other is not.
 
          if Needs_Finalization (DesigT)
            and then Needs_Finalization (T)


diff --git a/gcc/ada/exp_ch6.adb b/gcc/ada/exp_ch6.adb
--- a/gcc/ada/exp_ch6.adb
+++ b/gcc/ada/exp_ch6.adb
@@ -4913,7 +4913,7 @@  package body Exp_Ch6 is
       --  Optimization, if the returned value (which is on the sec-stack) is
       --  returned again, no need to copy/readjust/finalize, we can just pass
       --  the value thru (see Expand_N_Simple_Return_Statement), and thus no
-      --  attachment is needed
+      --  attachment is needed.
 
       if Nkind (Parent (N)) = N_Simple_Return_Statement then
          return;
@@ -7310,15 +7310,16 @@  package body Exp_Ch6 is
 
          Set_Enclosing_Sec_Stack_Return (N);
 
-         --  Optimize the case where the result is a function call. In this
-         --  case the result is already on the secondary stack and no further
-         --  processing is required except to set the By_Ref flag to ensure
-         --  that gigi does not attempt an extra unnecessary copy. (Actually
-         --  not just unnecessary but wrong in the case of a controlled type,
-         --  where gigi does not know how to do a copy.)
+         --  Optimize the case where the result is a function call that also
+         --  returns on the secondary stack. In this case the result is already
+         --  on the secondary stack and no further processing is required
+         --  except to set the By_Ref flag to ensure that gigi does not attempt
+         --  an extra unnecessary copy. (Actually not just unnecessary but
+         --  wrong in the case of a controlled type, where gigi does not know
+         --  how to do a copy.)
 
-         if Requires_Transient_Scope (Exp_Typ)
-           and then Exp_Is_Function_Call
+         pragma Assert (Requires_Transient_Scope (R_Type));
+         if Exp_Is_Function_Call and then Requires_Transient_Scope (Exp_Typ)
          then
             Set_By_Ref (N);
 
@@ -7849,7 +7850,7 @@  package body Exp_Ch6 is
 
       Compute_Returns_By_Ref (Subp);
 
-      --  Wnen freezing a null procedure, analyze its delayed aspects now
+      --  When freezing a null procedure, analyze its delayed aspects now
       --  because we may not have reached the end of the declarative list when
       --  delayed aspects are normally analyzed. This ensures that dispatching
       --  calls are properly rewritten when the generated _Postcondition
@@ -8219,10 +8220,6 @@  package body Exp_Ch6 is
          return False;
       end if;
 
-      --  For now we test whether E denotes a function or access-to-function
-      --  type whose result subtype is inherently limited. Later this test
-      --  may be revised to allow composite nonlimited types.
-
       if Ekind (E) in E_Function | E_Generic_Function
         or else (Ekind (E) = E_Subprogram_Type
                   and then Etype (E) /= Standard_Void_Type)


diff --git a/gcc/ada/exp_ch6.ads b/gcc/ada/exp_ch6.ads
--- a/gcc/ada/exp_ch6.ads
+++ b/gcc/ada/exp_ch6.ads
@@ -134,8 +134,11 @@  package Exp_Ch6 is
    --
    --  For inherently limited types in Ada 2005, True means that calls will
    --  actually be build-in-place in all cases. For other types, build-in-place
-   --  will be used when possible, but we need to make a copy at the call site
-   --  in some cases, notably assignment statements.
+   --  will be used when possible, but we need to make a copy in some
+   --  cases. For example, for "X := F(...);" if F can see X, or if F can
+   --  propagate exceptions, we need to store its result in a temp in general,
+   --  and copy the temp into X. Also, for "return Global_Var;" Global_Var
+   --  needs to be copied into the function result object.
 
    function Is_Build_In_Place_Function (E : Entity_Id) return Boolean;
    --  Ada 2005 (AI-318-02): Returns True if E denotes a function, generic


diff --git a/gcc/ada/exp_ch7.adb b/gcc/ada/exp_ch7.adb
--- a/gcc/ada/exp_ch7.adb
+++ b/gcc/ada/exp_ch7.adb
@@ -480,7 +480,7 @@  package body Exp_Ch7 is
       Skip_Self : Boolean := False) return Node_Id;
    --  Subsidiary to Make_Adjust_Call and Make_Final_Call. Given the entity of
    --  routine [Deep_]Adjust or [Deep_]Finalize and an object parameter, create
-   --  an adjust or finalization call. Wnen flag Skip_Self is set, the related
+   --  an adjust or finalization call. When flag Skip_Self is set, the related
    --  action has an effect on the components only (if any).
 
    function Make_Deep_Proc
@@ -8126,7 +8126,7 @@  package body Exp_Ch7 is
          --       end if;
          --       ...
 
-         --  When Deep_Adjust is invokes for field _parent, a value of False is
+         --  When Deep_Adjust is invoked for field _parent, a value of False is
          --  provided for the flag:
 
          --    Deep_Adjust (Obj._parent, False);