https://gcc.gnu.org/g:54c1b58486037fc18ade54cefff7410cfbee2267

commit r16-4058-g54c1b58486037fc18ade54cefff7410cfbee2267
Author: Bob Duff <d...@adacore.com>
Date:   Mon Sep 15 08:26:03 2025 -0400

    ada: Fix unnesting problem related to constructors
    
    This patch fixes a bug in unnesting, which is used by the llvm back end.
    
    Exp_Unst relies on the Scope field of nodes to detect up-level
    references. Temps created by Prepend_Constructor_Procedure_Prologue
    could have an incorrect Scope, causing Exp_Unst to use an up-level
    reference to an activation record to implement up-level references. That
    won't work; Exp_Unst is supposed to REMOVE up-level references.
    This patch corrects the Scope of such temps.
    
    gcc/ada/ChangeLog:
    
            * exp_ch6.adb (Prepend_Constructor_Procedure_Prologue):
            Push/Pop the procedure scope, so that temps created herein
            get the right Scope.

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

diff --git a/gcc/ada/exp_ch6.adb b/gcc/ada/exp_ch6.adb
index 5056b1f990fa..2a32f3a90592 100644
--- a/gcc/ada/exp_ch6.adb
+++ b/gcc/ada/exp_ch6.adb
@@ -6249,7 +6249,6 @@ package body Exp_Ch6 is
 
       procedure Prepend_Constructor_Procedure_Prologue
         (Spec_Id : Entity_Id; Body_Id : Entity_Id; L : List_Id);
-
       --  If N is the body of a constructor procedure (that is, a procedure
       --  named in a Constructor aspect specification for the type of the
       --  procedure's first parameter), then prepend and analyze the
@@ -6353,6 +6352,8 @@ package body Exp_Ch6 is
             return; -- the usual case
          end if;
 
+         Push_Scope (Spec_Id);
+
          --  Initialize the first parameter.
          --  First_Param_Type is a record type (tagged or untagged) or
          --  a type extension. If it is a type extension, then we begin by
@@ -6621,6 +6622,8 @@ package body Exp_Ch6 is
 
             Insert_List_Before_And_Analyze (First (L), Init_List);
          end;
+
+         Pop_Scope;
       end Prepend_Constructor_Procedure_Prologue;
 
       --  Local variables

Reply via email to