]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Get rid of N_Unchecked_Expression node
authorEric Botcazou <ebotcazou@adacore.com>
Fri, 25 Oct 2024 19:16:14 +0000 (21:16 +0200)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Tue, 12 Nov 2024 13:05:45 +0000 (14:05 +0100)
This node is used in a single place in the front-end: it wraps the newly
built N_Indexed_Component nodes on the left-hand side of assignments
generated to elaborate array aggregates, and its effect is to disable
range checks for the expressions of these nodes.

Most of the code in the front-end does not expect to encounter it at all,
which leads to weird effects when this actually happens after changes are
made to the processing of array aggregates.

This change replaces the node by the Kill_Range_Check flag already present
on N_Unchecked_Type_Conversion, but with a slightly adjusted semantics.

gcc/ada/ChangeLog:

* exp_aggr.adb (Build_Array_Aggr_Code.Gen_Assign): Do not call
Checks_Off on the newly built N_Indexed_Component node but instead
set Kill_Range_Check on it.
* exp_ch4.ads (Expand_N_Unchecked_Expression): Delete.
* exp_ch4.adb (Expand_N_Indexed_Component): Remove handling of
N_Unchecked_Expression.
(Expand_N_Unchecked_Expression): Delete.
(Expand_N_Unchecked_Type_Conversion): Propagate the Assignment_OK
flag and rewrite the node manually.
* exp_util.adb (Insert_Actions): Remove handling of
N_Unchecked_Expression.
(Side_Effect_Free): Likewise.
* expander.adb (Expand): Likewise.
* gen_il-gen-gen_nodes.adb (N_Indexed_Component): Add flag
Kill_Range_Check for the purpose of semantics.
(N_Unchecked_Expression): Delete.
* gen_il-internals.ads (Type_Frequency): Remove entry for
N_Unchecked_Expression.
* gen_il-types.ads (Opt_Type_Enum): Remove N_Unchecked_Expression.
* pprint.adb (Expression_Image): Remove handling of
N_Unchecked_Expression.
* sem.adb (Analyze): Likewise.
* sem_ch4.ads (Analyze_Unchecked_Expression): Delete.
* sem_ch4.adb (Analyze_Unchecked_Expression): Likewise.
* sem_res.adb (Resolve_Unchecked_Expression): Likewise.
(Resolve): Remove handling of N_Unchecked_Expression.
(Resolve_Indexed_Component): Do not call Apply_Scalar_Range_Check
on the expressions if Kill_Range_Check is set on the node.
* sem_util.adb (Is_Non_Preelaborable_Construct): Remove handling of
N_Unchecked_Expression.
* sinfo.ads (Kill_Range_Check): Document it for N_Indexed_Component.
(Unchecked Expression): Delete specification.
* sprint.adb (Sprint_Node_Actual): Remove handling of
N_Unchecked_Expression.
* tbuild.ads (Checks_Off): Delete.
* tbuild.adb (Checks_Off): Likewise.

18 files changed:
gcc/ada/exp_aggr.adb
gcc/ada/exp_ch4.adb
gcc/ada/exp_ch4.ads
gcc/ada/exp_util.adb
gcc/ada/expander.adb
gcc/ada/gen_il-gen-gen_nodes.adb
gcc/ada/gen_il-internals.ads
gcc/ada/gen_il-types.ads
gcc/ada/pprint.adb
gcc/ada/sem.adb
gcc/ada/sem_ch4.adb
gcc/ada/sem_ch4.ads
gcc/ada/sem_res.adb
gcc/ada/sem_util.adb
gcc/ada/sinfo.ads
gcc/ada/sprint.adb
gcc/ada/tbuild.adb
gcc/ada/tbuild.ads

index 8231e4006b16d2a5905ace0e6d7f152309f31aa0..d5e238baa59d5ecb427a7e193d4639d5042ba3cc 100644 (file)
@@ -1329,12 +1329,12 @@ package body Exp_Aggr is
          --  If we get here then we are at a bottom-level (sub-)aggregate
 
          Indexed_Comp :=
-           Checks_Off
-             (Make_Indexed_Component (Loc,
-                Prefix      => New_Copy_Tree (Into),
-                Expressions => New_Indexes));
+           Make_Indexed_Component (Loc,
+             Prefix      => New_Copy_Tree (Into),
+             Expressions => New_Indexes);
 
          Set_Assignment_OK (Indexed_Comp);
+         Set_Kill_Range_Check (Indexed_Comp);
 
          --  Ada 2005 (AI-287): In case of default initialized component, Expr
          --  is not present (and therefore we also initialize Expr_Q to empty).
index c16e09d9562da25c58d1c5bc88b2f0fc547b93f4..9e82b78e3b6b3b517953724fb1bbdb376c2f4fa4 100644 (file)
@@ -7307,10 +7307,7 @@ package body Exp_Ch4 is
 
       begin
          loop
-            if Nkind (Parnt) = N_Unchecked_Expression then
-               null;
-
-            elsif Nkind (Parnt) = N_Object_Renaming_Declaration then
+            if Nkind (Parnt) = N_Object_Renaming_Declaration then
                return;
 
             elsif Nkind (Parnt) in N_Subprogram_Call
@@ -12116,22 +12113,6 @@ package body Exp_Ch4 is
       end if;
    end Expand_N_Type_Conversion;
 
-   -----------------------------------
-   -- Expand_N_Unchecked_Expression --
-   -----------------------------------
-
-   --  Remove the unchecked expression node from the tree. Its job was simply
-   --  to make sure that its constituent expression was handled with checks
-   --  off, and now that is done, we can remove it from the tree, and indeed
-   --  must, since Gigi does not expect to see these nodes.
-
-   procedure Expand_N_Unchecked_Expression (N : Node_Id) is
-      Exp : constant Node_Id := Expression (N);
-   begin
-      Set_Assignment_OK (Exp, Assignment_OK (N) or else Assignment_OK (Exp));
-      Rewrite (N, Exp);
-   end Expand_N_Unchecked_Expression;
-
    ----------------------------------------
    -- Expand_N_Unchecked_Type_Conversion --
    ----------------------------------------
@@ -12150,7 +12131,11 @@ package body Exp_Ch4 is
       --  an Assignment_OK indication which must be propagated to the operand.
 
       if Operand_Type = Target_Type then
-         Expand_N_Unchecked_Expression (N);
+         if Assignment_OK (N) then
+            Set_Assignment_OK (Operand);
+         end if;
+
+         Rewrite (N, Operand);
          return;
       end if;
 
index 7bc777ea2ec91722e4501253e0f1a4485eb65e6c..22ffdc6496d14d2baa506125917089d58186623f 100644 (file)
@@ -71,7 +71,6 @@ package Exp_Ch4 is
    procedure Expand_N_Selected_Component          (N : Node_Id);
    procedure Expand_N_Slice                       (N : Node_Id);
    procedure Expand_N_Type_Conversion             (N : Node_Id);
-   procedure Expand_N_Unchecked_Expression        (N : Node_Id);
    procedure Expand_N_Unchecked_Type_Conversion   (N : Node_Id);
 
    function Build_Eq_Call
index df108918a742324625be1ed82db8b99ff3e7311e..767191060d822ad4b988a8f4c94892050e0415a1 100644 (file)
@@ -8340,7 +8340,6 @@ package body Exp_Util is
                | N_Terminate_Alternative
                | N_Triggering_Alternative
                | N_Type_Conversion
-               | N_Unchecked_Expression
                | N_Unchecked_Type_Conversion
                | N_Unconstrained_Array_Definition
                | N_Unused_At_End
@@ -14259,7 +14258,6 @@ package body Exp_Util is
 
          when N_Qualified_Expression
             | N_Type_Conversion
-            | N_Unchecked_Expression
          =>
             return Side_Effect_Free (Expression (N), Name_Req, Variable_Ref);
 
index 39b311fc1360d3e9fa6905f2fe811f0b6dd3979f..05dcbc0ea802c2a53905447d7654678dd4b5f7c8 100644 (file)
@@ -506,9 +506,6 @@ package body Expander is
                when N_Type_Conversion =>
                   Expand_N_Type_Conversion (N);
 
-               when N_Unchecked_Expression =>
-                  Expand_N_Unchecked_Expression (N);
-
                when N_Unchecked_Type_Conversion =>
                   Expand_N_Unchecked_Type_Conversion (N);
 
index e0e0538c5f0e9f70653c3ee62d123f3424016a43..b322f3ca81c5c3ab088a733fd29952b044874e95 100644 (file)
@@ -478,7 +478,8 @@ begin -- Gen_IL.Gen.Gen_Nodes
        (Sy (Prefix, Node_Id),
         Sy (Expressions, List_Id, Default_No_List),
         Sm (Atomic_Sync_Required, Flag),
-        Sm (Generalized_Indexing, Node_Id)));
+        Sm (Generalized_Indexing, Node_Id),
+        Sm (Kill_Range_Check, Flag)));
 
    Cc (N_Null, N_Subexpr);
 
@@ -575,9 +576,6 @@ begin -- Gen_IL.Gen.Gen_Nodes
         Sm (Float_Truncate, Flag),
         Sm (Rounded_Result, Flag)));
 
-   Cc (N_Unchecked_Expression, N_Subexpr,
-       (Sy (Expression, Node_Id, Default_Empty)));
-
    Cc (N_Unchecked_Type_Conversion, N_Subexpr,
        (Sy (Subtype_Mark, Node_Id, Default_Empty),
         Sy (Expression, Node_Id, Default_Empty),
index 31e81c1feb5c550953af749bd1e502c1c6330c8e..46d38d0baaa5c76859d05c0bffc388c11ce9f70a 100644 (file)
@@ -458,7 +458,6 @@ package Gen_IL.Internals is
       E_Generic_Function => 1292, -- (0.000) 41 slots
       E_Enumeration_Type => 1186, -- (0.000) 47 slots
       N_Enumeration_Type_Definition => 1169, -- (0.000) 6 slots
-      N_Unchecked_Expression => 1112, -- (0.000) 7 slots
       N_Op_Or => 1107, -- (0.000) 8 slots
       N_Designator => 1100, -- (0.000) 9 slots
       N_Formal_Discrete_Type_Definition => 1086, -- (0.000) 4 slots
index 4a739043faa09bd9d983ef4c22910a28664204ee..66e9b695ce03164a1163ce78797ff00e3842e5ea 100644 (file)
@@ -271,7 +271,6 @@ package Gen_IL.Types is
       N_Slice,
       N_Target_Name,
       N_Type_Conversion,
-      N_Unchecked_Expression,
       N_Unchecked_Type_Conversion,
       N_Subtype_Indication,
       N_Component_Declaration,
index fbf0e59239ab411d5ba6d4218e65d353e9a784aa..b5935fcb0b470892339f22bf01364aa0e6019d0a 100644 (file)
@@ -424,9 +424,7 @@ package body Pprint is
                   end if;
                end;
 
-            when N_Expression_With_Actions
-               | N_Unchecked_Expression
-            =>
+            when N_Expression_With_Actions =>
                return Expr_Name (Expression (Expr));
 
             when N_Raise_Constraint_Error =>
index cfd0493527487216285c811ae04c1dc4810e7c9d..c6d65ea713a104911eb42c675585d48478ed0c87 100644 (file)
@@ -613,9 +613,6 @@ package body Sem is
          when N_Type_Conversion =>
             Analyze_Type_Conversion (N);
 
-         when N_Unchecked_Expression =>
-            Analyze_Unchecked_Expression (N);
-
          when N_Unchecked_Type_Conversion =>
             Analyze_Unchecked_Type_Conversion (N);
 
index c1f6622db1e45b307a533d7ad1710b05a8efea12..ad18e824457c0da31515ea9abebb10e67abfceef 100644 (file)
@@ -6488,19 +6488,6 @@ package body Sem_Ch4 is
       Operator_Check (N);
    end Analyze_Unary_Op;
 
-   ----------------------------------
-   -- Analyze_Unchecked_Expression --
-   ----------------------------------
-
-   procedure Analyze_Unchecked_Expression (N : Node_Id) is
-      Expr : constant Node_Id := Expression (N);
-
-   begin
-      Analyze (Expr, Suppress => All_Checks);
-      Set_Etype (N, Etype (Expr));
-      Save_Interps (Expr, N);
-   end Analyze_Unchecked_Expression;
-
    ---------------------------------------
    -- Analyze_Unchecked_Type_Conversion --
    ---------------------------------------
index dbe0f9a73daf2c94418b62089515878bc548e278..574613dc38b3d3be2e1fe67548a24ccdcf18344f 100644 (file)
@@ -50,7 +50,6 @@ package Sem_Ch4  is
    procedure Analyze_Slice                     (N : Node_Id);
    procedure Analyze_Type_Conversion           (N : Node_Id);
    procedure Analyze_Unary_Op                  (N : Node_Id);
-   procedure Analyze_Unchecked_Expression      (N : Node_Id);
    procedure Analyze_Unchecked_Type_Conversion (N : Node_Id);
 
    procedure Ambiguous_Operands (N : Node_Id);
index 658f9eb2b7243676cf095e6e5cd400eac17d3717..d2b019aef173bd549189d89684f26f1105812605 100644 (file)
@@ -242,7 +242,6 @@ package body Sem_Res is
    procedure Resolve_Target_Name               (N : Node_Id; Typ : Entity_Id);
    procedure Resolve_Type_Conversion           (N : Node_Id; Typ : Entity_Id);
    procedure Resolve_Unary_Op                  (N : Node_Id; Typ : Entity_Id);
-   procedure Resolve_Unchecked_Expression      (N : Node_Id; Typ : Entity_Id);
    procedure Resolve_Unchecked_Type_Conversion (N : Node_Id; Typ : Entity_Id);
 
    function Operator_Kind
@@ -3534,9 +3533,6 @@ package body Sem_Res is
             when N_Type_Conversion =>
                Resolve_Type_Conversion           (N, Ctx_Type);
 
-            when N_Unchecked_Expression =>
-               Resolve_Unchecked_Expression      (N, Ctx_Type);
-
             when N_Unchecked_Type_Conversion =>
                Resolve_Unchecked_Type_Conversion (N, Ctx_Type);
          end case;
@@ -9730,7 +9726,9 @@ package body Sem_Res is
             Resolve (Expr, Etype (Index));
             Check_Unset_Reference (Expr);
 
-            Apply_Scalar_Range_Check (Expr, Etype (Index));
+            if not Kill_Range_Check (N) then
+               Apply_Scalar_Range_Check (Expr, Etype (Index));
+            end if;
 
             Next_Index (Index);
             Next (Expr);
@@ -12871,19 +12869,6 @@ package body Sem_Res is
       end;
    end Resolve_Unary_Op;
 
-   ----------------------------------
-   -- Resolve_Unchecked_Expression --
-   ----------------------------------
-
-   procedure Resolve_Unchecked_Expression
-     (N   : Node_Id;
-      Typ : Entity_Id)
-   is
-   begin
-      Resolve (Expression (N), Typ, Suppress => All_Checks);
-      Set_Etype (N, Typ);
-   end Resolve_Unchecked_Expression;
-
    ---------------------------------------
    -- Resolve_Unchecked_Type_Conversion --
    ---------------------------------------
index 25f164f8736b997f358c61bc644cb69d4c645f93..b1b3891dd65b232f482e5c3ffab22a06e37fad30 100644 (file)
@@ -18483,7 +18483,6 @@ package body Sem_Util is
             when N_Allocator
                | N_Qualified_Expression
                | N_Type_Conversion
-               | N_Unchecked_Expression
                | N_Unchecked_Type_Conversion
             =>
                --  Subpool_Handle_Name and Subtype_Mark are left out because
index 7ed6fad6709407033099fd21a009b8d2f5414afb..09385e95586e93b82d6e83ec1c7c2e4acc6f5a12 100644 (file)
@@ -1909,9 +1909,11 @@ package Sinfo is
    --    for further details.
 
    --  Kill_Range_Check
-   --    Used in an N_Unchecked_Type_Conversion node to indicate that the
-   --    result should not be subjected to range checks. This is used for the
-   --    implementation of Normalize_Scalars.
+   --    Used in N_Indexed_Component to indicate that its expressions should
+   --    not be subjected to range checks and in N_Unchecked_Type_Conversion
+   --    to indicate that the result of the conversion should not be subjected
+   --    to range checks. This is used for the implementation of aggregates and
+   --    Normalize_Scalars respectively.
 
    --  Label_Construct
    --    Used in an N_Implicit_Label_Declaration node. Refers to an N_Label,
@@ -3830,8 +3832,9 @@ package Sinfo is
       --  Sloc contains a copy of the Sloc value of the Prefix
       --  Prefix
       --  Expressions
-      --  Generalized_Indexing
       --  Atomic_Sync_Required
+      --  Generalized_Indexing
+      --  Kill_Range_Check
       --  plus fields for expression
 
       --  Note: if any of the subscripts requires a range check, then the
@@ -8428,28 +8431,6 @@ package Sinfo is
       --  with the N_In node (or a rewriting thereof) corresponding to a
       --  classwide membership test.
 
-      --------------------------
-      -- Unchecked Expression --
-      --------------------------
-
-      --  An unchecked expression is one that must be analyzed and resolved
-      --  with all checks off, regardless of the current setting of scope
-      --  suppress flags.
-
-      --  Sprint syntax: `(expression)
-
-      --  Note: this node is always removed from the tree (and replaced by
-      --  its constituent expression) on completion of analysis, so it only
-      --  appears in intermediate trees, and will never be seen by Gigi.
-
-      --  N_Unchecked_Expression
-      --  Sloc is a copy of the Sloc of the expression
-      --  Expression
-      --  plus fields for expression
-
-      --  Note: in the case where a debug source file is generated, the Sloc
-      --  for this node points to the back quote in the Sprint file output.
-
       -------------------------------
       -- Unchecked Type Conversion --
       -------------------------------
index 321fd7f99a9beb09ef24a664dd5f507d73894deb..614bcc17b14e383177cc89c47577279ba77ed52b 100644 (file)
@@ -3550,12 +3550,6 @@ package body Sprint is
             Sprint_Node (Expression (Node));
             Write_Char (')');
 
-         when N_Unchecked_Expression =>
-            Col_Check (10);
-            Write_Str ("`(");
-            Sprint_Node_Sloc (Expression (Node));
-            Write_Char (')');
-
          when N_Unchecked_Type_Conversion =>
             Sprint_Node (Subtype_Mark (Node));
             Write_Char ('!');
index b538911e8bc73b09b3ccd62c15d26925ab400a2b..31154266bcb4c6eca12593ff2e5841e6eea0a796 100644 (file)
@@ -99,17 +99,6 @@ package body Tbuild is
       end if;
    end Add_Unique_Serial_Number;
 
-   ----------------
-   -- Checks_Off --
-   ----------------
-
-   function Checks_Off (N : Node_Id) return Node_Id is
-   begin
-      return
-        Make_Unchecked_Expression (Sloc (N),
-          Expression => N);
-   end Checks_Off;
-
    ----------------
    -- Convert_To --
    ----------------
index 64296e68c183e14ba65227c57d8adbd16b7e6355..e818bcd002134b0d40e9782d068da0e9090b29fa 100644 (file)
@@ -34,12 +34,6 @@ with Uintp;          use Uintp;
 
 package Tbuild is
 
-   function Checks_Off (N : Node_Id) return Node_Id;
-   pragma Inline (Checks_Off);
-   --  Returns an N_Unchecked_Expression node whose expression is the given
-   --  argument. The results is a subexpression identical to the argument,
-   --  except that it will be analyzed and resolved with checks off.
-
    function Convert_To (Typ : Entity_Id; Expr : Node_Id) return Node_Id;
    --  Returns an expression that is a type conversion of expression Expr to
    --  type Typ. If the type of Expr is Typ, then no conversion is required.