]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Fix internal error on call with parameter of predicated subtype
authorEric Botcazou <ebotcazou@adacore.com>
Thu, 28 Sep 2023 13:53:36 +0000 (15:53 +0200)
committerEric Botcazou <ebotcazou@adacore.com>
Wed, 20 Dec 2023 14:45:54 +0000 (15:45 +0100)
The problem is that the predicated subtype does not inherit all the required
attributes of a string subtype with a static predicate.

gcc/ada/
* sem_ch3.adb (Analyze_Subtype_Declaration): Remove a short-circuit
for subtypes without aspects when it comes to predicates.
* sem_util.adb (Inherit_Predicate_Flags): Deal with private subtypes
whose full view is an Itype.

gcc/ada/sem_ch3.adb
gcc/ada/sem_util.adb

index 2e9f8aace1a5a0d9bee787a14aef9b318aaac9f6..6a6d870f9785ca3f32361599c6814bee1093fc36 100644 (file)
@@ -5961,17 +5961,10 @@ package body Sem_Ch3 is
       --  If this is a subtype declaration for an actual in an instance,
       --  inherit static and dynamic predicates if any.
 
-      --  If declaration has no aspect specifications, inherit predicate
-      --  info as well. Unclear how to handle the case of both specified
-      --  and inherited predicates ??? Other inherited aspects, such as
-      --  invariants, should be OK, but the combination with later pragmas
-      --  may also require special merging.
-
       if Has_Predicates (T)
         and then Present (Predicate_Function (T))
-        and then
-          ((In_Instance and then not Comes_From_Source (N))
-             or else No (Aspect_Specifications (N)))
+        and then In_Instance
+        and then not Comes_From_Source (N)
       then
          --  Inherit Subprograms_For_Type from the full view, if present
 
index 4d8c7e62751bf186eca15556246b4e441f057198..90ac9d7ca2c181b8b1e0f62c6536712c809bf1e7 100644 (file)
@@ -14612,10 +14612,17 @@ package body Sem_Util is
       --  A named subtype does not inherit the predicate function of its
       --  parent but an itype declared for a loop index needs the discrete
       --  predicate information of its parent to execute the loop properly.
+      --  Moreover, a named private subtype whose full view is an itype also
+      --  needs to inherit a predicate function because it will not be frozen.
       --  A non-discrete type may has a static predicate (for example True)
       --  but has no static_discrete_predicate.
 
-      if Is_Itype (Subt) and then Present (Predicate_Function (Par)) then
+      if (Is_Itype (Subt)
+           or else (Ekind (Subt) = E_Private_Subtype
+                     and then Present (Full_View (Subt))
+                     and then Is_Itype (Full_View (Subt))))
+        and then Present (Predicate_Function (Par))
+      then
          Set_Subprograms_For_Type (Subt, Subprograms_For_Type (Par));
 
          if Has_Static_Predicate (Par) and then Is_Discrete_Type (Par) then