]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Fix for validity checking of limited scalar types
authorPiotr Trojanek <trojanek@adacore.com>
Tue, 28 Jan 2025 11:12:23 +0000 (12:12 +0100)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Fri, 6 Jun 2025 08:37:02 +0000 (10:37 +0200)
With a recent change we are now validity checking objects of private scalar
types, but need to handle private scalar types whose public view is limited.

gcc/ada/ChangeLog:

* checks.adb (Insert_Valid_Check): Set flag Assignment_OK in the object
declaration inserted for the validity checks.

gcc/ada/checks.adb

index dcfcaa33bcc482ff9fad53246521be8e8e2c6a5c..6a98292d1cc163f09a786bfe2955a066b961664a 100644 (file)
@@ -8163,6 +8163,7 @@ package body Checks is
       end if;
 
       declare
+         Decl   : Node_Id;
          CE     : Node_Id;
          PV     : Node_Id;
          Var_Id : Entity_Id;
@@ -8215,12 +8216,20 @@ package body Checks is
             Mutate_Ekind (Var_Id, E_Variable);
             Set_Etype (Var_Id, Typ);
 
-            Insert_Action (Exp,
+            Decl :=
               Make_Object_Declaration (Loc,
                 Defining_Identifier => Var_Id,
                 Object_Definition   => New_Occurrence_Of (Typ, Loc),
-                Expression          => New_Copy_Tree (Exp)),
-              Suppress => Validity_Check);
+                Expression          => New_Copy_Tree (Exp));
+
+            --  We might be validity-checking object whose type is declared as
+            --  limited but completion is a scalar type. We need to explicitly
+            --  flag its assignment as OK, as otherwise it would be rejected by
+            --  the language rules.
+
+            Set_Assignment_OK (Decl);
+
+            Insert_Action (Exp, Decl, Suppress => Validity_Check);
 
             Set_Validated_Object (Var_Id, New_Copy_Tree (Exp));