]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: No need to follow New_Occurrence_Of with Set_Etype
authorPiotr Trojanek <trojanek@adacore.com>
Fri, 23 Feb 2024 12:57:27 +0000 (13:57 +0100)
committerMarc Poulhiès <poulhies@adacore.com>
Thu, 16 May 2024 08:49:31 +0000 (10:49 +0200)
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.

gcc/ada/exp_ch13.adb
gcc/ada/sem_util.adb

index 2d5ee9b6e80347b7df5e8f150ebff41da93a627d..af8c925586c49b8b3bba2a03c9e0753ce8bf5168 100644 (file)
@@ -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;
 
index 766cabfc109da1f8b19cb8022c0ddaa4830296cf..5ebb1319de7ef7e82f643fa007cfe83680216fef 100644 (file)
@@ -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