public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [COMMITTED] ada: Crash processing type invariants on child subprogram
@ 2023-09-19 11:27 Marc Poulhiès
  0 siblings, 0 replies; only message in thread
From: Marc Poulhiès @ 2023-09-19 11:27 UTC (permalink / raw)
  To: gcc-patches; +Cc: Javier Miranda

From: Javier Miranda <miranda@adacore.com>

gcc/ada/

	* contracts.adb
	(Has_Public_Visibility_Of_Subprogram): Add missing support for
	child subprograms.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/contracts.adb | 25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)

diff --git a/gcc/ada/contracts.adb b/gcc/ada/contracts.adb
index 77578dacc18..4aaa276495b 100644
--- a/gcc/ada/contracts.adb
+++ b/gcc/ada/contracts.adb
@@ -2484,7 +2484,7 @@ package body Contracts is
                --  declarations of the package containing the type, or in the
                --  visible declaration of a child unit of that package.
 
-               else
+               elsif Is_List_Member (Subp_Decl) then
                   declare
                      Decls      : constant List_Id   :=
                                     List_Containing (Subp_Decl);
@@ -2508,6 +2508,29 @@ package body Contracts is
                                  (Specification
                                    (Unit_Declaration_Node (Subp_Scope))));
                   end;
+
+               --  Determine whether the subprogram is a child subprogram of
+               --  of the package containing the type.
+
+               else
+                  pragma Assert
+                    (Nkind (Parent (Subp_Decl)) = N_Compilation_Unit);
+
+                  declare
+                     Subp_Scope : constant Entity_Id :=
+                                    Scope (Defining_Entity (Subp_Decl));
+                     Typ_Scope  : constant Entity_Id := Scope (Typ);
+
+                  begin
+                     return
+                       Ekind (Subp_Scope) = E_Package
+                         and then
+                           (Typ_Scope = Subp_Scope
+                              or else
+                                (Is_Child_Unit (Subp_Scope)
+                                   and then Is_Ancestor_Package
+                                              (Typ_Scope, Subp_Scope)));
+                  end;
                end if;
             end Has_Public_Visibility_Of_Subprogram;
 
-- 
2.40.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-09-19 11:27 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-19 11:27 [COMMITTED] ada: Crash processing type invariants on child subprogram 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).