]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Fix Itype-related predicate check omissions (part 2).
authorSteve Baird <baird@adacore.com>
Mon, 21 Apr 2025 18:57:30 +0000 (11:57 -0700)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Mon, 30 Jun 2025 13:47:22 +0000 (15:47 +0200)
Add to the previous fix for this issue to better handle cases where
GNATProve calls Einfo.Utils.Predicate_Function, passing in an Itype.

gcc/ada/ChangeLog:

* einfo-utils.adb (Predicate_Function): Look through an Itype if
that takes us to another subtype of the same type.

gcc/ada/einfo-utils.adb

index 60ee509da674a231c5647046488012e801825a57..417da6e828bc6ff326b94468a4103f4a8f1b4d85 100644 (file)
@@ -2345,6 +2345,25 @@ package body Einfo.Utils is
    begin
       pragma Assert (Is_Type (Id));
 
+      if Nkind (Associated_Node_For_Itype (Id)) = N_Subtype_Declaration then
+         declare
+            Associated_Id : constant Entity_Id :=
+              Defining_Identifier (Associated_Node_For_Itype (Id));
+         begin
+            --  Avoid Itype/predicate problems by looking through Itypes.
+            --  We never introduce new predicates for Itypes, so doing this
+            --  will never cause us to incorrectly overlook a predicate.
+            --  It is not clear whether the FE needs this fix, but
+            --  GNATProve does (note that GNATProve calls Predicate_Function).
+
+            if Id /= Associated_Id
+              and then Base_Type (Id) = Base_Type (Associated_Id)
+            then
+               return Predicate_Function (Associated_Id);
+            end if;
+         end;
+      end if;
+
       --  If type is private and has a completion, predicate may be defined on
       --  the full view.