When an assignment of an allocator the type of which has predicate
checks is made inside of a record, GNAT generates a call to the
predicate function. However, before this commit, GNAT wouldn't check if
the subtype mark had a predicate, which would result in the predicate
check function not being called if no temporary was created for the
designated object.

Tested on x86_64-pc-linux-gnu, committed on trunk

2020-06-11  Ghjuvan Lacambre  <lacam...@adacore.com>

gcc/ada/

        * exp_ch3.adb (Build_Assignment): Generate predicate check if
        subtype mark has predicate.
--- gcc/ada/exp_ch3.adb
+++ gcc/ada/exp_ch3.adb
@@ -1998,6 +1998,20 @@ package body Exp_Ch3 is
             Append (Make_Predicate_Check (Typ, Exp), Res);
          end if;
 
+         if Nkind (Exp) = N_Allocator
+            and then Nkind (Expression (Exp)) = N_Qualified_Expression
+         then
+            declare
+               Subtype_Entity : constant Entity_Id
+                  := Entity (Subtype_Mark (Expression (Exp)));
+            begin
+               if Has_Predicates (Subtype_Entity) then
+                  Append (Make_Predicate_Check
+                     (Subtype_Entity, Expression (Expression (Exp))), Res);
+               end if;
+            end;
+         end if;
+
          return Res;
 
       exception

Reply via email to