https://gcc.gnu.org/g:197dfdca778234286dfcb8b5cb91af93e24e4341

commit r16-6638-g197dfdca778234286dfcb8b5cb91af93e24e4341
Author: Denis Mazzucato <[email protected]>
Date:   Thu Dec 18 13:34:18 2025 +0100

    ada: Fix crash on legality check for initialization of implicit constructor
    
    This patch fixes a crash occurring during the legality check of the 
Initialize
    aspect when the constructor is implicitly created by the compiler, e.g., the
    default copy constructor. In such case, Corresponding_Spec is not 
available, the
    Specification field must be used instead.
    
    gcc/ada/ChangeLog:
    
            * sem_ch13.adb (Check_Constructor_Initialization_Expression): The 
first
            parameter of an implicit constructor comes from Specification, not
            Corresponding_Spec.

Diff:
---
 gcc/ada/sem_ch13.adb | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb
index 06a98e4305aa..38732cf58be2 100644
--- a/gcc/ada/sem_ch13.adb
+++ b/gcc/ada/sem_ch13.adb
@@ -3305,8 +3305,7 @@ package body Sem_Ch13 is
             procedure Check_Constructor_Initialization_Expression
               (Expr : Node_Id; Aspect_Name : String)
             is
-               First_Parameter : constant Entity_Id :=
-                 First_Entity (Corresponding_Spec (N));
+               First_Parameter : Entity_Id;
 
                --  Flag error if N refers to the forbidden entity
                function Check_Node_For_Bad_Reference
@@ -3324,7 +3323,7 @@ package body Sem_Ch13 is
                   then
                      Error_Msg_N
                        ("constructed object referenced in " &
-                       Aspect_Name & " aspect_specification", N);
+                        Aspect_Name & " aspect_specification", N);
                   end if;
 
                   return OK;
@@ -3333,6 +3332,16 @@ package body Sem_Ch13 is
                procedure Check_Tree_For_Bad_Reference is
                  new Traverse_Proc (Check_Node_For_Bad_Reference);
             begin
+               --  If coming from an implicit constructor, the Self parameter
+               --  is retrieved via the specification's defining unit name.
+
+               if Acts_As_Spec (N) then
+                  First_Parameter :=
+                    First_Entity (Defining_Unit_Name (Specification (N)));
+               else
+                  First_Parameter := First_Entity (Corresponding_Spec (N));
+               end if;
+
                Check_Tree_For_Bad_Reference (Expr);
             end Check_Constructor_Initialization_Expression;

Reply via email to