public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Marc Poulhiès" <poulhies@adacore.com>
To: gcc-patches@gcc.gnu.org
Cc: Gary Dismukes <dismukes@adacore.com>
Subject: [COMMITTED] ada: Compiler hangs on container aggregate with function call as key expression
Date: Tue, 19 Dec 2023 15:30:59 +0100	[thread overview]
Message-ID: <20231219143059.455817-1-poulhies@adacore.com> (raw)

From: Gary Dismukes <dismukes@adacore.com>

The compiler hangs (or may crash, if assertions are enabled) when compiling
an iterated association of a container aggregate that has a key expression
given by a function call. The resolution of the call leads to a blowup in
Build_Call_Marker, because the temporary copy of the expression that's
analyzed has an Empty parent, causing insertion of the call marker to fail.
The fix for this is to preanalyze, rather than analyze, the copy of the key
expression (Build_Call_Marker will return without creating a call marker in
the case of preanalysis).

gcc/ada/

	* sem_aggr.adb (Resolve_Iterated_Association): Call
	Preanalyze_And_Resolve instead of Analyze_And_Resolve on a key
	expression of an iterated association.

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

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

diff --git a/gcc/ada/sem_aggr.adb b/gcc/ada/sem_aggr.adb
index a61326c9ae2..bf249620d04 100644
--- a/gcc/ada/sem_aggr.adb
+++ b/gcc/ada/sem_aggr.adb
@@ -3270,13 +3270,13 @@ package body Sem_Aggr is
                             (Iterator_Specification (Comp)));
             end if;
 
-            --  Key expression must have the type of the key. We analyze
+            --  Key expression must have the type of the key. We preanalyze
             --  a copy of the original expression, because it will be
             --  reanalyzed and copied as needed during expansion of the
             --  corresponding loop.
 
             Key_Expr := Key_Expression (Comp);
-            Analyze_And_Resolve (New_Copy_Tree (Key_Expr), Key_Type);
+            Preanalyze_And_Resolve (New_Copy_Tree (Key_Expr), Key_Type);
             End_Scope;
 
             Typ := Key_Type;
-- 
2.43.0


                 reply	other threads:[~2023-12-19 14:31 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231219143059.455817-1-poulhies@adacore.com \
    --to=poulhies@adacore.com \
    --cc=dismukes@adacore.com \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).