From: Bob Duff <d...@adacore.com> The compiler crashes on an assignment statement of the form "X.Y := new T;", where X.Y is an expanded name (i.e. not a record component or similar) and T is a type containing tasks.
gcc/ada/ChangeLog: * exp_util.adb (Build_Task_Image_Decls): Deal properly with the case of an expanded name. Minor cleanup: use a case statement instead of if/elsif chain. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/exp_util.adb | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/gcc/ada/exp_util.adb b/gcc/ada/exp_util.adb index 99aacc763a1..dd284e2a20d 100644 --- a/gcc/ada/exp_util.adb +++ b/gcc/ada/exp_util.adb @@ -4396,6 +4396,10 @@ package body Exp_Util is Nkind (Parent (Id_Ref)) = N_Assignment_Statement and then Nkind (Expression (Parent (Id_Ref))) = N_Allocator; + Id : constant Node_Id := + (if Nkind (Id_Ref) = N_Expanded_Name then Selector_Name (Id_Ref) + else Id_Ref); + -- Replace expanded_name X.Y with Y Component_Suffix_Index : constant Int := (if In_Init_Proc then -1 else 0); @@ -4421,11 +4425,10 @@ package body Exp_Util is Expression => Make_String_Literal (Loc, Strval => String_From_Name_Buffer))); + end if; - else - if Nkind (Id_Ref) = N_Identifier - or else Nkind (Id_Ref) = N_Defining_Identifier - then + case Nkind (Id) is + when N_Identifier | N_Defining_Identifier => -- For a simple variable, the image of the task is built from -- the name of the variable. To avoid possible conflict with the -- anonymous type created for a single protected object, add a @@ -4433,29 +4436,31 @@ package body Exp_Util is T_Id := Make_Defining_Identifier (Loc, - New_External_Name (Chars (Id_Ref), 'T', 1)); + New_External_Name (Chars (Id), 'T', 1)); - Get_Name_String (Chars (Id_Ref)); + Get_Name_String (Chars (Id)); Expr := Make_String_Literal (Loc, Strval => String_From_Name_Buffer); - elsif Nkind (Id_Ref) = N_Selected_Component then + when N_Selected_Component => T_Id := Make_Defining_Identifier (Loc, - New_External_Name (Chars (Selector_Name (Id_Ref)), 'T', + New_External_Name (Chars (Selector_Name (Id)), 'T', Suffix_Index => Component_Suffix_Index)); - Fun := Build_Task_Record_Image (Loc, Id_Ref, Is_Dyn); + Fun := Build_Task_Record_Image (Loc, Id, Is_Dyn); - elsif Nkind (Id_Ref) = N_Indexed_Component then + when N_Indexed_Component => T_Id := Make_Defining_Identifier (Loc, New_External_Name (Chars (A_Type), 'N')); - Fun := Build_Task_Array_Image (Loc, Id_Ref, A_Type, Is_Dyn); - end if; - end if; + Fun := Build_Task_Array_Image (Loc, Id, A_Type, Is_Dyn); + + when others => + raise Program_Error; + end case; if Present (Fun) then Append (Fun, Decls); -- 2.43.0