]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
2017-10-20 Bob Duff <duff@adacore.com>
authorpmderodat <pmderodat@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 20 Oct 2017 14:51:32 +0000 (14:51 +0000)
committerpmderodat <pmderodat@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 20 Oct 2017 14:51:32 +0000 (14:51 +0000)
* sinfo.ads, sinfo.adb (Alloc_For_BIP_Return): New flag to indicate
that an allocator came from a b-i-p return statement.
* exp_ch4.adb (Expand_Allocator_Expression): Avoid adjusting the return
object of a nonlimited build-in-place function call.
* exp_ch6.adb (Expand_N_Extended_Return_Statement): Set the
Alloc_For_BIP_Return flag on generated allocators.
* sem_ch5.adb (Analyze_Assignment): Move Assert to where it can't fail.
If the N_Assignment_Statement has been transformed into something else,
then Should_Transform_BIP_Assignment won't work.
* exp_ch3.adb (Expand_N_Object_Declaration): A previous revision said,
"Remove Adjust if we're building the return object of an extended
return statement in place." Back out that part of the change, because
the Alloc_For_BIP_Return flag is now used for that.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@253940 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ada/ChangeLog
gcc/ada/exp_ch3.adb
gcc/ada/exp_ch4.adb
gcc/ada/exp_ch6.adb
gcc/ada/sem_ch5.adb
gcc/ada/sinfo.adb
gcc/ada/sinfo.ads

index f3d7209ff5b8ea374297515785004d09fbae4310..af7038eaa795916bb6febbaf02c6b18c1d435bc2 100644 (file)
@@ -1,3 +1,19 @@
+2017-10-20  Bob Duff  <duff@adacore.com>
+
+       * sinfo.ads, sinfo.adb (Alloc_For_BIP_Return): New flag to indicate
+       that an allocator came from a b-i-p return statement.
+       * exp_ch4.adb (Expand_Allocator_Expression): Avoid adjusting the return
+       object of a nonlimited build-in-place function call.
+       * exp_ch6.adb (Expand_N_Extended_Return_Statement): Set the
+       Alloc_For_BIP_Return flag on generated allocators.
+       * sem_ch5.adb (Analyze_Assignment): Move Assert to where it can't fail.
+       If the N_Assignment_Statement has been transformed into something else,
+       then Should_Transform_BIP_Assignment won't work.
+       * exp_ch3.adb (Expand_N_Object_Declaration): A previous revision said,
+       "Remove Adjust if we're building the return object of an extended
+       return statement in place." Back out that part of the change, because
+       the Alloc_For_BIP_Return flag is now used for that.
+
 2017-10-19  Bob Duff  <duff@adacore.com>
 
        * exp_ch6.adb (Is_Build_In_Place_Result_Type): Fix silly bug -- "Typ"
index 837c8a98d86e5b5ccf971f4777ca49305147f704..ea739384d697f80961a20a084012a162f6ec106a 100644 (file)
@@ -6800,15 +6800,7 @@ package body Exp_Ch3 is
             --  adjustment is required if we are going to rewrite the object
             --  declaration into a renaming declaration.
 
-            if Is_Build_In_Place_Result_Type (Typ)
-              and then Nkind (Parent (N)) = N_Extended_Return_Statement
-              and then
-                not Is_Definite_Subtype (Etype (Return_Applies_To
-                      (Return_Statement_Entity (Parent (N)))))
-            then
-               null;
-
-            elsif Needs_Finalization (Typ)
+            if Needs_Finalization (Typ)
               and then not Is_Limited_View (Typ)
               and then not Rewrite_As_Renaming
             then
index 770341ce9eb713d50dcff3e4b02d3fba4c32870f..7a72a366c6d024a2636f48dbbcb2c9b7dcdad65a 100644 (file)
@@ -1069,12 +1069,15 @@ package body Exp_Ch4 is
          --  object can be limited but not inherently limited if this allocator
          --  came from a return statement (we're allocating the result on the
          --  secondary stack). In that case, the object will be moved, so we do
-         --  want to Adjust.
+         --  want to Adjust. However, if it's a nonlimited build-in-place
+         --  function call, Adjust is not wanted.
 
          if Needs_Finalization (DesigT)
            and then Needs_Finalization (T)
            and then not Aggr_In_Place
            and then not Is_Limited_View (T)
+           and then not Alloc_For_BIP_Return (N)
+           and then not Is_Build_In_Place_Function_Call (Expression (N))
          then
             --  An unchecked conversion is needed in the classwide case because
             --  the designated type can be an ancestor of the subtype mark of
index ecef075a85ea4dd029acf21f419cc25fd00a81d5..593a0d041ccc445f2c515448d261b23e83e6debf 100644 (file)
@@ -5145,11 +5145,19 @@ package body Exp_Ch6 is
                         Set_No_Initialization (Heap_Allocator);
                      end if;
 
+                     --  Set the flag indicating that the allocator came from
+                     --  a build-in-place return statement, so we can avoid
+                     --  adjusting the allocated object. Note that this flag
+                     --  will be inherited by the copies made below.
+
+                     Set_Alloc_For_BIP_Return (Heap_Allocator);
+
                      --  The Pool_Allocator is just like the Heap_Allocator,
                      --  except we set Storage_Pool and Procedure_To_Call so
                      --  it will use the user-defined storage pool.
 
                      Pool_Allocator := New_Copy_Tree (Heap_Allocator);
+                     pragma Assert (Alloc_For_BIP_Return (Pool_Allocator));
 
                      --  Do not generate the renaming of the build-in-place
                      --  pool parameter on ZFP because the parameter is not
@@ -5191,6 +5199,7 @@ package body Exp_Ch6 is
 
                      else
                         SS_Allocator := New_Copy_Tree (Heap_Allocator);
+                        pragma Assert (Alloc_For_BIP_Return (SS_Allocator));
 
                         --  The heap and pool allocators are marked as
                         --  Comes_From_Source since they correspond to an
index 8c92669876c545ffe050425797ca7c873a9145cb..10002ea08c2a4ce84025af79302b7d7898bb9ba6 100644 (file)
@@ -1090,12 +1090,14 @@ package body Sem_Ch5 is
       --  the context of the assignment statement. Restore the expander mode
       --  now so that assignment statement can be properly expanded.
 
-      if Nkind (N) = N_Assignment_Statement and then Has_Target_Names (N) then
-         Expander_Mode_Restore;
-         Full_Analysis := Save_Full_Analysis;
-      end if;
+      if Nkind (N) = N_Assignment_Statement then
+         if Has_Target_Names (N) then
+            Expander_Mode_Restore;
+            Full_Analysis := Save_Full_Analysis;
+         end if;
 
-      pragma Assert (not Should_Transform_BIP_Assignment (Typ => T1));
+         pragma Assert (not Should_Transform_BIP_Assignment (Typ => T1));
+      end if;
    end Analyze_Assignment;
 
    -----------------------------
index e4f8608eb73a075e87e5b05ceb714db0856ddcec..dc4e8fb2c1a0ef2a3f0faa119e01306ac76a8a0c 100644 (file)
@@ -203,6 +203,14 @@ package body Sinfo is
       return Flag4 (N);
    end Aliased_Present;
 
+   function Alloc_For_BIP_Return
+      (N : Node_Id) return Boolean is
+   begin
+      pragma Assert (False
+        or else NT (N).Nkind = N_Allocator);
+      return Flag1 (N);
+   end Alloc_For_BIP_Return;
+
    function All_Others
       (N : Node_Id) return Boolean is
    begin
@@ -3626,6 +3634,14 @@ package body Sinfo is
       Set_Flag4 (N, Val);
    end Set_Aliased_Present;
 
+   procedure Set_Alloc_For_BIP_Return
+      (N : Node_Id; Val : Boolean := True) is
+   begin
+      pragma Assert (False
+        or else NT (N).Nkind = N_Allocator);
+      Set_Flag1 (N, Val);
+   end Set_Alloc_For_BIP_Return;
+
    procedure Set_All_Others
       (N : Node_Id; Val : Boolean := True) is
    begin
index 9030c7c1176cb8607192612699142b925b33097a..c0dfe73a1cdf850db15dc3ff1ef887a576fa0201 100644 (file)
@@ -903,6 +903,10 @@ package Sinfo is
    --    known at compile time, this field points to an N_Range node with those
    --    bounds. Otherwise Empty.
 
+   --  Alloc_For_BIP_Return (Flag1-Sem)
+   --    Present in N_Allocator nodes. True if the allocator is one of those
+   --    generated for a build-in-place return statement.
+
    --  All_Others (Flag11-Sem)
    --    Present in an N_Others_Choice node. This flag is set for an others
    --    exception where all exceptions are to be caught, even those that are
@@ -4773,6 +4777,7 @@ package Sinfo is
       --  Subpool_Handle_Name (Node4) (set to Empty if not present)
       --  Storage_Pool (Node1-Sem)
       --  Procedure_To_Call (Node2-Sem)
+      --  Alloc_For_BIP_Return (Flag1-Sem)
       --  Null_Exclusion_Present (Flag11)
       --  No_Initialization (Flag13-Sem)
       --  Is_Static_Coextension (Flag14-Sem)
@@ -7837,7 +7842,7 @@ package Sinfo is
 
       --  The required semantics is that the set of actions is executed in
       --  the order in which it appears, as though they appeared by themselves
-      --  in the enclosing list of declarations of statements. Unlike what
+      --  in the enclosing list of declarations or statements. Unlike what
       --  happens when using an N_Block_Statement, no new scope is introduced.
 
       --  Note: for the time being, this is used only as a transient
@@ -9125,6 +9130,9 @@ package Sinfo is
    function Aliased_Present
      (N : Node_Id) return Boolean;    -- Flag4
 
+   function Alloc_For_BIP_Return
+     (N : Node_Id) return Boolean;    -- Flag1
+
    function All_Others
      (N : Node_Id) return Boolean;    -- Flag11
 
@@ -10214,6 +10222,9 @@ package Sinfo is
    procedure Set_Aliased_Present
      (N : Node_Id; Val : Boolean := True);    -- Flag4
 
+   procedure Set_Alloc_For_BIP_Return
+     (N : Node_Id; Val : Boolean := True);    -- Flag1
+
    procedure Set_All_Others
      (N : Node_Id; Val : Boolean := True);    -- Flag11
 
@@ -13063,6 +13074,7 @@ package Sinfo is
    pragma Inline (Address_Warning_Posted);
    pragma Inline (Aggregate_Bounds);
    pragma Inline (Aliased_Present);
+   pragma Inline (Alloc_For_BIP_Return);
    pragma Inline (All_Others);
    pragma Inline (All_Present);
    pragma Inline (Alternatives);
@@ -13423,6 +13435,7 @@ package Sinfo is
    pragma Inline (Set_Address_Warning_Posted);
    pragma Inline (Set_Aggregate_Bounds);
    pragma Inline (Set_Aliased_Present);
+   pragma Inline (Set_Alloc_For_BIP_Return);
    pragma Inline (Set_All_Others);
    pragma Inline (Set_All_Present);
    pragma Inline (Set_Alternatives);