[Ada] Generate predicate checks for on assignments in records
authorGhjuvan Lacambre <lacambre@adacore.com>
Thu, 12 Mar 2020 13:12:53 +0000 (14:12 +0100)
committerPierre-Marie de Rodat <derodat@adacore.com>
Thu, 11 Jun 2020 09:53:33 +0000 (05:53 -0400)
2020-06-11  Ghjuvan Lacambre  <lacambre@adacore.com>

gcc/ada/

* exp_ch3.adb (Build_Assignment): Generate predicate check if
subtype mark has predicate.

gcc/ada/exp_ch3.adb

index 3bc1f60..f412deb 100644 (file)
@@ -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