]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Fix unnesting problem related to constructors
authorBob Duff <duff@adacore.com>
Mon, 15 Sep 2025 12:26:03 +0000 (08:26 -0400)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Tue, 23 Sep 2025 13:01:13 +0000 (15:01 +0200)
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.

gcc/ada/exp_ch6.adb

index 5056b1f990fa47206b8f936634ce454bdf92bb27..2a32f3a905927eb0f0f0c976d94516902fd70944 100644 (file)
@@ -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