]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Follow up fixes for Put_Image/streaming regressions
authorSteve Baird <baird@adacore.com>
Thu, 15 Feb 2024 00:27:59 +0000 (16:27 -0800)
committerMarc Poulhiès <poulhies@adacore.com>
Tue, 14 May 2024 08:19:58 +0000 (10:19 +0200)
A recent change to reduce duplication of compiler-generated Put_Image and
streaming subprograms introduced two regressions. One is yet another of the
many cases where generating these routines "on demand" (as opposed at the
point of the associated type declaration) requires loosening the compiler's
enforcement of privacy. The other is a use-before-definition issue that
occurs because the declaration of a Put_Image procedure is not hoisted far
enough.

gcc/ada/

* exp_attr.adb (Build_And_Insert_Type_Attr_Subp): If a subprogram
associated with a (library-level) type declared in another unit is
to be inserted somewhere in a list, then insert it at the head of
the list.
* sem_ch5.adb (Analyze_Assignment): Normally a limited-type
assignment is illegal. Relax this rule if Comes_From_Source is
False and the type is not immutably limited.

gcc/ada/exp_attr.adb
gcc/ada/sem_ch5.adb

index 6dba600620ec78a518bf6f5769d23a6c76aa3b30..e12e8b4a439af34d2c335ee775337f9f2e5b4d05 100644 (file)
@@ -1953,7 +1953,8 @@ package body Exp_Attr is
 
             while Present (Ancestor) loop
                if Is_List_Member (Ancestor) then
-                  Insertion_Point := Ancestor;
+                  Insertion_Point := First (List_Containing (Ancestor));
+                  pragma Assert (Present (Insertion_Point));
                end if;
                Ancestor := Parent (Ancestor);
             end loop;
index 65370ebfe7ea794166515feb8dfa458878706b35..1e09e57919e1b464c7ba426afb19541f0e57f215 100644 (file)
@@ -597,10 +597,13 @@ package body Sem_Ch5 is
 
       --  Error of assigning to limited type. We do however allow this in
       --  certain cases where the front end generates the assignments.
+      --  Comes_From_Source test is needed to allow compiler-generated
+      --  streaming/put_image subprograms, which may ignore privacy.
 
       elsif Is_Limited_Type (T1)
         and then not Assignment_OK (Lhs)
         and then not Assignment_OK (Original_Node (Lhs))
+        and then (Comes_From_Source (N) or Is_Immutably_Limited_Type (T1))
       then
          --  CPP constructors can only be called in declarations