]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[Ada] Make Declaration_Node return nondeclarations in fewer cases
authorBob Duff <duff@adacore.com>
Mon, 6 Sep 2021 17:01:04 +0000 (13:01 -0400)
committerPierre-Marie de Rodat <derodat@adacore.com>
Mon, 25 Oct 2021 15:07:21 +0000 (15:07 +0000)
gcc/ada/

* einfo-utils.adb (Declaration_Node): Avoid returning the
following node kinds: N_Assignment_Statement, N_Integer_Literal,
N_Procedure_Call_Statement, N_Subtype_Indication, and
N_Type_Conversion.  Assert that the result is in N_Is_Decl or
empty.
* gen_il-gen-gen_nodes.adb (N_Is_Decl): Modify to match the
things that Declaration_Node can return.

gcc/ada/einfo-utils.adb
gcc/ada/gen_il-gen-gen_nodes.adb

index eb90d181190474efe2049f8a308ab297456ce2f3..763b646242894ee387106a76a0e0ada40a2d52ee 100644 (file)
@@ -698,6 +698,30 @@ package body Einfo.Utils is
          P := Empty;
       end if;
 
+      --  Declarations are sometimes removed by replacing them with other
+      --  irrelevant nodes. For example, a declare expression can be turned
+      --  into a literal by constant folding. In these cases we want to
+      --  return Empty.
+
+      if Nkind (P) in
+          N_Assignment_Statement
+        | N_Integer_Literal
+        | N_Procedure_Call_Statement
+        | N_Subtype_Indication
+        | N_Type_Conversion
+      then
+         P := Empty;
+      end if;
+
+      --  The following Assert indicates what kinds of nodes can be returned;
+      --  they are not all "declarations".
+
+      if Serious_Errors_Detected = 0 then
+         pragma Assert
+           (Nkind (P) in N_Is_Decl | N_Empty,
+            "Declaration_Node incorrect kind: " & Node_Kind'Image (Nkind (P)));
+      end if;
+
       return P;
    end Declaration_Node;
 
index 3b6bd68cbd984b83c15a4686e4e42b9c9e93d52f..712577325a083e1ee661a4f136000c900686f7ae 100644 (file)
@@ -1675,16 +1675,29 @@ begin -- Gen_IL.Gen.Gen_Nodes
 
    Union (N_Is_Decl,
           Children =>
-            (N_Declaration,
+            (N_Aggregate,
+             N_Block_Statement,
+             N_Declaration,
              N_Discriminant_Specification,
+             N_Entry_Index_Specification,
              N_Enumeration_Type_Definition,
              N_Exception_Handler,
+             N_Explicit_Dereference,
+             N_Expression_With_Actions,
+             N_Extension_Aggregate,
+             N_Identifier,
+             N_Iterated_Component_Association,
              N_Later_Decl_Item,
+             N_Loop_Statement,
+             N_Null_Statement,
+             N_Number_Declaration,
              N_Package_Specification,
              N_Parameter_Specification,
              N_Renaming_Declaration,
-             N_Subprogram_Specification));
-   --  Nodes that can be returned by Declaration_Node
+             N_Quantified_Expression));
+   --  Nodes that can be returned by Declaration_Node; it can also return
+   --  Empty. Not all of these are true "declarations", but Declaration_Node
+   --  can return them in some cases.
 
    Union (N_Is_Range,
           Children =>