https://gcc.gnu.org/g:00c7f2296fbad17a54629f571da42104f1054478
commit r15-471-g00c7f2296fbad17a54629f571da42104f1054478 Author: Steve Baird <ba...@adacore.com> Date: Wed Feb 14 16:27:59 2024 -0800 ada: Follow up fixes for Put_Image/streaming regressions 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. Diff: --- gcc/ada/exp_attr.adb | 3 ++- gcc/ada/sem_ch5.adb | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/gcc/ada/exp_attr.adb b/gcc/ada/exp_attr.adb index 6dba600620ec..e12e8b4a439a 100644 --- a/gcc/ada/exp_attr.adb +++ b/gcc/ada/exp_attr.adb @@ -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; diff --git a/gcc/ada/sem_ch5.adb b/gcc/ada/sem_ch5.adb index 65370ebfe7ea..1e09e57919e1 100644 --- a/gcc/ada/sem_ch5.adb +++ b/gcc/ada/sem_ch5.adb @@ -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