]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[Ada] Compiler aborts on a constrained subtype of a predicated type
authorEd Schonberg <schonberg@adacore.com>
Mon, 21 Dec 2020 01:18:33 +0000 (20:18 -0500)
committerPierre-Marie de Rodat <derodat@adacore.com>
Mon, 3 May 2021 09:28:20 +0000 (05:28 -0400)
gcc/ada/

* sem_util.adb (Build_Constrained_Itype): Remove prior patch,
issue is better handled in Sem_Ch13.Build_Predicate_Functions.
* sem_ch13.adb (Build_Predicate_Functions): Do not build
predicate function for an Itype with a defined
Predicated_Parent, even if that designated parent does not yet
have a Predicate_Function. This can happen in instance bodies
nested within a generic unit.

gcc/ada/sem_ch13.adb
gcc/ada/sem_util.adb

index c8631545815da25e619463a98f1901a54998a40b..005c7b0cf508924b4f77464f32d6b7cd78e803f7 100644 (file)
@@ -9976,11 +9976,23 @@ package body Sem_Ch13 is
    --  Start of processing for Build_Predicate_Functions
 
    begin
-      --  Return if already built or if type does not have predicates
+      --  Return if already built, if type does not have predicates,
+      --  or if type is a constructed subtype that will inherit a
+      --  predicate function from its ancestor. In a generic context
+      --  the predicated parent may not have a predicate function yet
+      --  but we don't want to build a new one for the subtype. This can
+      --  happen in an instance body which is nested within a generic
+      --  unit, in which case Within_A_Generic may be false, SId is
+      --  Empty, but uses of Typ will receive a predicate check in a
+      --  context where expansion and tests are enabled.
 
       SId := Predicate_Function (Typ);
       if not Has_Predicates (Typ)
         or else (Present (SId) and then Has_Completion (SId))
+        or else
+          (Is_Itype (Typ)
+           and then not Comes_From_Source (Typ)
+           and then Present (Predicated_Parent (Typ)))
       then
          return;
 
index a64cbde17edfb1d80c72952e44ea54dd25f64cc6..b7b622dbcca9f1d9fa0b3f5f6e3a6fdd0230a1a4 100644 (file)
@@ -2380,14 +2380,6 @@ package body Sem_Util is
 
       Analyze (Subtyp_Decl, Suppress => All_Checks);
 
-      --  In addition, inhibit the generation of predicate functions for
-      --  this subtype, because its declaration is not in a declarative
-      --  list, and no predicates apply to the aggregate itself, but only
-      --  to the object to which it may be assigned.
-
-      Set_Has_Dynamic_Predicate_Aspect (Def_Id, False);
-      Set_Has_Predicates (Def_Id, False);
-
       Set_Etype (N, Def_Id);
    end Build_Constrained_Itype;