aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Baird <baird@adacore.com>2024-02-14 16:27:59 -0800
committerMarc Poulhiès <poulhies@adacore.com>2024-05-14 10:19:58 +0200
commit00c7f2296fbad17a54629f571da42104f1054478 (patch)
tree71f7a53182e1673073e9f21f6272a1a01e507111
parentf5798041ac97347e52d985be37f049c6d902d282 (diff)
downloadgcc-00c7f2296fbad17a54629f571da42104f1054478.zip
gcc-00c7f2296fbad17a54629f571da42104f1054478.tar.gz
gcc-00c7f2296fbad17a54629f571da42104f1054478.tar.bz2
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.
-rw-r--r--gcc/ada/exp_attr.adb3
-rw-r--r--gcc/ada/sem_ch5.adb3
2 files changed, 5 insertions, 1 deletions
diff --git a/gcc/ada/exp_attr.adb b/gcc/ada/exp_attr.adb
index 6dba600..e12e8b4 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 65370eb..1e09e57 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