https://gcc.gnu.org/g:f5c78702f9436bfa5a0cf1f87b6004ead79c5892

commit r15-557-gf5c78702f9436bfa5a0cf1f87b6004ead79c5892
Author: Piotr Trojanek <troja...@adacore.com>
Date:   Fri Feb 23 13:57:27 2024 +0100

    ada: No need to follow New_Occurrence_Of with Set_Etype
    
    Routine New_Occurrence_Of itself sets the Etype of its result; there is
    no need to set it explicitly afterwards.
    
    Code cleanup related to fix for attribute 'Old; semantics is unaffected.
    
    gcc/ada/
    
            * exp_ch13.adb (Expand_N_Free_Statement): After analysis, the
            new temporary has the type of its Object_Definition and the new
            occurrence of this temporary has this type as well; simplify.
            * sem_util.adb
            (Indirect_Temp_Value): Remove redundant call to Set_Etype;
            simplify.
            (Is_Access_Type_For_Indirect_Temp): Add missing body header.

Diff:
---
 gcc/ada/exp_ch13.adb |  9 ++-------
 gcc/ada/sem_util.adb | 11 +++++++----
 2 files changed, 9 insertions(+), 11 deletions(-)

diff --git a/gcc/ada/exp_ch13.adb b/gcc/ada/exp_ch13.adb
index 2d5ee9b6e803..af8c925586c4 100644
--- a/gcc/ada/exp_ch13.adb
+++ b/gcc/ada/exp_ch13.adb
@@ -358,21 +358,16 @@ package body Exp_Ch13 is
          declare
             Expr_Typ : constant Entity_Id  := Etype (Expr);
             Loc      : constant Source_Ptr := Sloc (N);
-            New_Expr : Node_Id;
-            Temp_Id  : Entity_Id;
+            Temp_Id  : constant Entity_Id  := Make_Temporary (Loc, 'T');
 
          begin
-            Temp_Id := Make_Temporary (Loc, 'T');
             Insert_Action (N,
               Make_Object_Declaration (Loc,
                 Defining_Identifier => Temp_Id,
                 Object_Definition   => New_Occurrence_Of (Expr_Typ, Loc),
                 Expression          => Relocate_Node (Expr)));
 
-            New_Expr := New_Occurrence_Of (Temp_Id, Loc);
-            Set_Etype (New_Expr, Expr_Typ);
-
-            Set_Expression (N, New_Expr);
+            Set_Expression (N, New_Occurrence_Of (Temp_Id, Loc));
          end;
       end if;
 
diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb
index 766cabfc109d..5ebb1319de7e 100644
--- a/gcc/ada/sem_util.adb
+++ b/gcc/ada/sem_util.adb
@@ -31081,8 +31081,7 @@ package body Sem_Util is
          begin
             if Is_Anonymous_Access_Type (Typ) then
                --  No indirection in this case; just evaluate the temp.
-               Result := New_Occurrence_Of (Temp, Loc);
-               Set_Etype (Result, Etype (Temp));
+               return New_Occurrence_Of (Temp, Loc);
 
             else
                Result := Make_Explicit_Dereference (Loc,
@@ -31101,11 +31100,15 @@ package body Sem_Util is
 
                   Set_Etype (Result, Typ);
                end if;
-            end if;
 
-            return Result;
+               return Result;
+            end if;
          end Indirect_Temp_Value;
 
+         --------------------------------------
+         -- Is_Access_Type_For_Indirect_Temp --
+         --------------------------------------
+
          function Is_Access_Type_For_Indirect_Temp
            (T : Entity_Id) return Boolean is
          begin

Reply via email to