diff mbox series

[COMMITTED,22/35] ada: No need to follow New_Occurrence_Of with Set_Etype

Message ID 20240516092606.41242-22-poulhies@adacore.com
State New
Headers show
Series [COMMITTED,01/35] ada: Fix docs and comments about pragmas for Boolean-valued aspects | expand

Commit Message

Marc Poulhiès May 16, 2024, 9:25 a.m. UTC
From: Piotr Trojanek <trojanek@adacore.com>

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.

Tested on x86_64-pc-linux-gnu, committed on master.

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

Patch

diff --git a/gcc/ada/exp_ch13.adb b/gcc/ada/exp_ch13.adb
index 2d5ee9b6e80..af8c925586c 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 766cabfc109..5ebb1319de7 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