aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorBob Duff <duff@adacore.com>2021-09-06 13:01:04 -0400
committerPierre-Marie de Rodat <derodat@adacore.com>2021-10-25 15:07:21 +0000
commit93c63f32a2cb49679143f4b893343fcba6f59351 (patch)
tree400595ed159056d7d9571d8844462873eb871f7b /gcc
parenta3a6a0a50af2dd257682289703b721ba1b7863ca (diff)
downloadgcc-93c63f32a2cb49679143f4b893343fcba6f59351.zip
gcc-93c63f32a2cb49679143f4b893343fcba6f59351.tar.gz
gcc-93c63f32a2cb49679143f4b893343fcba6f59351.tar.bz2
[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.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ada/einfo-utils.adb24
-rw-r--r--gcc/ada/gen_il-gen-gen_nodes.adb19
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 =>