public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [COMMITTED] ada: Deep delta aggregates in postconditions
@ 2023-11-21 10:00 Marc Poulhiès
  0 siblings, 0 replies; only message in thread
From: Marc Poulhiès @ 2023-11-21 10:00 UTC (permalink / raw)
  To: gcc-patches; +Cc: Steve Baird

From: Steve Baird <baird@adacore.com>

Fix a bug in handling array-valued deep delta aggregates occurring in
postconditions. The bug could result in a spurious compilation failure.

gcc/ada/

	* sem_aggr.adb (Resolve_Delta_Array_Aggregate): In the case of a
	deep delta choice, the expected type for the expression will
	typically not be the component type of the array type, so a call
	to Analyze_And_Resolve that assumes otherwise would be an error.
	It turns out that such a call, while wrong, is usually harmless
	because the expression has already been marked as analyzed. This
	doesn't work if the aggregate occurs in a postcondition and, in
	any case, we don't want to rely on this. So do not perform the
	call in the deep case.

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

---
 gcc/ada/sem_aggr.adb | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/gcc/ada/sem_aggr.adb b/gcc/ada/sem_aggr.adb
index 46a96a31a00..d3f9a773191 100644
--- a/gcc/ada/sem_aggr.adb
+++ b/gcc/ada/sem_aggr.adb
@@ -3696,6 +3696,8 @@ package body Sem_Aggr is
       Choice : Node_Id;
       Expr   : Node_Id;
 
+      Deep_Choice_Seen : Boolean := False;
+
    begin
       Assoc := First (Deltas);
       while Present (Assoc) loop
@@ -3750,6 +3752,7 @@ package body Sem_Aggr is
             while Present (Choice) loop
                if Is_Deep_Choice (Choice, Typ) then
                   pragma Assert (All_Extensions_Allowed);
+                  Deep_Choice_Seen := True;
 
                   --  a deep delta aggregate
                   Resolve_Deep_Delta_Assoc (Assoc, Typ);
@@ -3794,7 +3797,7 @@ package body Sem_Aggr is
             if Box_Present (Assoc) then
                Error_Msg_N
                  ("'<'> in array delta aggregate is not allowed", Assoc);
-            else
+            elsif not Deep_Choice_Seen then
                Analyze_And_Resolve (Expression (Assoc), Component_Type (Typ));
             end if;
          end if;
-- 
2.42.0


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

only message in thread, other threads:[~2023-11-21 10:00 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-21 10:00 [COMMITTED] ada: Deep delta aggregates in postconditions 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).