public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [COMMITTED] ada: Follow up fixes for Put_Image/streaming regressions
@ 2024-05-14  8:23 Marc Poulhiès
  0 siblings, 0 replies; only message in thread
From: Marc Poulhiès @ 2024-05-14  8:23 UTC (permalink / raw)
  To: gcc-patches; +Cc: Steve Baird

From: Steve Baird <baird@adacore.com>

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.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 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 6dba600620e..e12e8b4a439 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 65370ebfe7e..1e09e57919e 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
 
-- 
2.43.2


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-05-14  8:23 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-14  8:23 [COMMITTED] ada: Follow up fixes for Put_Image/streaming regressions Marc Poulhiès

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).