From: Denis Mazzucato <[email protected]>
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.
Tested on x86_64-pc-linux-gnu (before the recent bootstrap breakage), committed
on master.
---
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 06a98e4305a..38732cf58be 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;
--
2.51.0