public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-4680] [Ada] Make Declaration_Node return nondeclarations in fewer cases
@ 2021-10-25 15:08 Pierre-Marie de Rodat
0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2021-10-25 15:08 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:93c63f32a2cb49679143f4b893343fcba6f59351
commit r12-4680-g93c63f32a2cb49679143f4b893343fcba6f59351
Author: Bob Duff <duff@adacore.com>
Date: Mon Sep 6 13:01:04 2021 -0400
[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.
Diff:
---
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 eb90d181190..763b6462428 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 3b6bd68cbd9..712577325a0 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 =>
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-10-25 15:08 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-25 15:08 [gcc r12-4680] [Ada] Make Declaration_Node return nondeclarations in fewer cases Pierre-Marie de Rodat
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).