https://gcc.gnu.org/g:74a7c286be8259bd645fad68cbb356cad18403d8

commit r16-1808-g74a7c286be8259bd645fad68cbb356cad18403d8
Author: Steve Baird <ba...@adacore.com>
Date:   Mon Apr 21 11:57:30 2025 -0700

    ada: Fix Itype-related predicate check omissions (part 2).
    
    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.

Diff:
---
 gcc/ada/einfo-utils.adb | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/gcc/ada/einfo-utils.adb b/gcc/ada/einfo-utils.adb
index 60ee509da674..417da6e828bc 100644
--- a/gcc/ada/einfo-utils.adb
+++ b/gcc/ada/einfo-utils.adb
@@ -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.

Reply via email to