From 93c63f32a2cb49679143f4b893343fcba6f59351 Mon Sep 17 00:00:00 2001 From: Bob Duff Date: Mon, 6 Sep 2021 13:01:04 -0400 Subject: [PATCH] [Ada] Make Declaration_Node return nondeclarations in fewer cases 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 | 24 ++++++++++++++++++++++++ gcc/ada/gen_il-gen-gen_nodes.adb | 19 ++++++++++++++++--- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/gcc/ada/einfo-utils.adb b/gcc/ada/einfo-utils.adb index eb90d18..763b646 100644 --- a/gcc/ada/einfo-utils.adb +++ b/gcc/ada/einfo-utils.adb @@ -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; diff --git a/gcc/ada/gen_il-gen-gen_nodes.adb b/gcc/ada/gen_il-gen-gen_nodes.adb index 3b6bd68..7125773 100644 --- a/gcc/ada/gen_il-gen-gen_nodes.adb +++ b/gcc/ada/gen_il-gen-gen_nodes.adb @@ -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 => -- 2.7.4