* [COMMITTED] ada: Fix list of inherited subprograms in query for GNATprove
@ 2023-07-04 8:09 Marc Poulhiès
0 siblings, 0 replies; only message in thread
From: Marc Poulhiès @ 2023-07-04 8:09 UTC (permalink / raw)
To: gcc-patches; +Cc: Yannick Moy
From: Yannick Moy <moy@adacore.com>
The query Inherited_Subprograms was returning a list containing
some subprograms whose overridding was also in the list, when
interfaces was present. This was an issue for GNATprove. Now propose
a mode for this function to filter out overridden primitives.
gcc/ada/
* sem_disp.adb (Inherited_Subprograms): Add parameter to filter
out results.
* sem_disp.ads: Likewise.
Tested on x86_64-pc-linux-gnu, committed on master.
---
gcc/ada/sem_disp.adb | 30 ++++++++++++++++++++++++++++++
gcc/ada/sem_disp.ads | 5 +++++
2 files changed, 35 insertions(+)
diff --git a/gcc/ada/sem_disp.adb b/gcc/ada/sem_disp.adb
index 6c8212c3cb3..b22407aafb8 100644
--- a/gcc/ada/sem_disp.adb
+++ b/gcc/ada/sem_disp.adb
@@ -2530,6 +2530,7 @@ package body Sem_Disp is
(S : Entity_Id;
No_Interfaces : Boolean := False;
Interfaces_Only : Boolean := False;
+ Skip_Overridden : Boolean := False;
One_Only : Boolean := False) return Subprogram_List
is
Result : Subprogram_List (1 .. 6000);
@@ -2670,6 +2671,34 @@ package body Sem_Disp is
end if;
end if;
+ -- Do not keep an overridden operation if its overridding operation
+ -- is in the results too, and it is not S. This can happen for
+ -- inheritance between interfaces.
+
+ if Skip_Overridden then
+ declare
+ Res : constant Subprogram_List (1 .. N) := Result (1 .. N);
+ M : Nat := 0;
+ begin
+ for J in 1 .. N loop
+ for K in 1 .. N loop
+ if Res (K) /= S
+ and then Res (J) = Overridden_Operation (Res (K))
+ then
+ goto Skip;
+ end if;
+ end loop;
+
+ M := M + 1;
+ Result (M) := Res (J);
+
+ <<Skip>>
+ end loop;
+
+ N := M;
+ end;
+ end if;
+
<<Done>>
return Result (1 .. N);
@@ -2702,6 +2731,7 @@ package body Sem_Disp is
(S : Entity_Id;
No_Interfaces : Boolean := False;
Interfaces_Only : Boolean := False;
+ Skip_Overridden : Boolean := False;
One_Only : Boolean := False) return Subprogram_List renames
Inheritance_Utilities_Inst.Inherited_Subprograms;
diff --git a/gcc/ada/sem_disp.ads b/gcc/ada/sem_disp.ads
index 1e6c9e6f65a..a2cfec881f1 100644
--- a/gcc/ada/sem_disp.ads
+++ b/gcc/ada/sem_disp.ads
@@ -120,6 +120,7 @@ package Sem_Disp is
(S : Entity_Id;
No_Interfaces : Boolean := False;
Interfaces_Only : Boolean := False;
+ Skip_Overridden : Boolean := False;
One_Only : Boolean := False) return Subprogram_List;
function Is_Overriding_Subprogram (E : Entity_Id) return Boolean;
@@ -129,6 +130,7 @@ package Sem_Disp is
(S : Entity_Id;
No_Interfaces : Boolean := False;
Interfaces_Only : Boolean := False;
+ Skip_Overridden : Boolean := False;
One_Only : Boolean := False) return Subprogram_List;
-- Given the spec of a subprogram, this function gathers any inherited
-- subprograms from direct inheritance or via interfaces. The result is an
@@ -143,6 +145,9 @@ package Sem_Disp is
-- subprograms inherited from interfaces. At most one of No_Interfaces
-- and Interfaces_Only should be True.
--
+ -- If Skip_Overridden is True, subprograms overridden by another subprogram
+ -- in the result list are skipped.
+ --
-- If One_Only is set, the search is discontinued as soon as one entry
-- is found. In this case the resulting array is either null or contains
-- exactly one element.
--
2.40.0
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-07-04 8:09 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-04 8:09 [COMMITTED] ada: Fix list of inherited subprograms in query for GNATprove Marc Poulhiès
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).