[COMMITTED,7/9] ada: GNAT-LLVM compiler crash on container aggregates with iterators

Message ID 20240806090241.576862-7-poulhies@adacore.com
State Committed
Commit c0c1e02070f3b05eb9cd0001028be45bbe847ced
Headers
Series [COMMITTED,1/9] ada: Reject use-clause conflicts in the run-time library |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 warning Patch is already merged
linaro-tcwg-bot/tcwg_gcc_build--master-arm warning Patch is already merged

Commit Message

Marc Poulhiès Aug. 6, 2024, 9:02 a.m. UTC
  From: Gary Dismukes <dismukes@adacore.com>

Recent fixes for container aggregates with iterated element associations
exposed a latent bug with loops that are wrapped in blocks, where the loop
entity's scope was not adjusted to reflect the new enclosing block scope.

gcc/ada/

	* sem_ch5.adb (Analyze_Loop_Statement.Wrap_Loop_Statement): Remove
	the loop Entity_Id from its old scope and insert it in the new
	block scope that wraps it.

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

---
 gcc/ada/sem_ch5.adb | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
  

Patch

diff --git a/gcc/ada/sem_ch5.adb b/gcc/ada/sem_ch5.adb
index d44a12d1dd1..30fee6e6500 100644
--- a/gcc/ada/sem_ch5.adb
+++ b/gcc/ada/sem_ch5.adb
@@ -3800,8 +3800,9 @@  package body Sem_Ch5 is
          procedure Wrap_Loop_Statement (Manage_Sec_Stack : Boolean) is
             Loc : constant Source_Ptr := Sloc (N);
 
-            Blk    : Node_Id;
-            Blk_Id : Entity_Id;
+            Blk     : Node_Id;
+            Blk_Id  : Entity_Id;
+            Loop_Id : constant Entity_Id := Entity (Identifier (N));
 
          begin
             Blk :=
@@ -3816,6 +3817,12 @@  package body Sem_Ch5 is
 
             Rewrite (N, Blk);
             Analyze (N);
+
+            --  Transfer the loop entity from its old scope to the new block
+            --  scope.
+
+            Remove_Entity (Loop_Id);
+            Append_Entity (Loop_Id, Blk_Id);
          end Wrap_Loop_Statement;
 
          --  Local variables