From f76647c2ec8c53d40d3f011d35ab2a3691eda62c Mon Sep 17 00:00:00 2001 From: Arnaud Charlet Date: Thu, 21 Apr 2016 11:54:42 +0200 Subject: [PATCH] [multiple changes] 2016-04-21 Hristian Kirtchev * exp_pakd.adb, sem_ch13.adb: Minor reformatting. 2016-04-21 Ed Schonberg * exp_dbug.adb, exp_dbug.ads (Qualify_Entity_Name): Add suffixes to disambiguate local variables that may be hidden from inner visibility by nested block declarations or loop variables. From-SVN: r235327 --- gcc/ada/ChangeLog | 10 ++++++ gcc/ada/exp_dbug.adb | 29 ++++++++++++++++ gcc/ada/exp_dbug.ads | 17 ++++++++- gcc/ada/exp_pakd.adb | 83 ++++++++++++++++++++++---------------------- gcc/ada/sem_ch13.adb | 4 +-- 5 files changed, 98 insertions(+), 45 deletions(-) diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index 27476846f1b..602116bfbeb 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,13 @@ +2016-04-21 Hristian Kirtchev + + * exp_pakd.adb, sem_ch13.adb: Minor reformatting. + +2016-04-21 Ed Schonberg + + * exp_dbug.adb, exp_dbug.ads (Qualify_Entity_Name): Add suffixes to + disambiguate local variables that may be hidden from inner visibility + by nested block declarations or loop variables. + 2016-04-21 Jerome Lambourg * s-soflin.adb: Initialize the Stack_Limit global variable. diff --git a/gcc/ada/exp_dbug.adb b/gcc/ada/exp_dbug.adb index 1f706d6bca5..df0543d4cb0 100644 --- a/gcc/ada/exp_dbug.adb +++ b/gcc/ada/exp_dbug.adb @@ -1458,6 +1458,35 @@ package body Exp_Dbug is else Set_Has_Qualified_Name (Ent); + + -- If a variable is hidden by a subsequent loop variable, qualify + -- the name of that loop variable to prevent visibility issues when + -- translating to C. Note that gdb probably never handled properly + -- this accidental hiding, given that loops are not scopes at + -- runtime. We also qualify a name if it hides an outer homonym, + -- and both are declared in blocks. + + if Modify_Tree_For_C and then Ekind (Ent) = E_Variable then + if Present (Hiding_Loop_Variable (Ent)) then + declare + Var : constant Entity_Id := Hiding_Loop_Variable (Ent); + + begin + Set_Entity_Name (Var); + Add_Str_To_Name_Buffer ("L"); + Set_Chars (Var, Name_Enter); + end; + + elsif Present (Homonym (Ent)) + and then Ekind (Scope (Ent)) = E_Block + and then Ekind (Scope (Homonym (Ent))) = E_Block + then + Set_Entity_Name (Ent); + Add_Str_To_Name_Buffer ("B"); + Set_Chars (Ent, Name_Enter); + end if; + end if; + return; end if; diff --git a/gcc/ada/exp_dbug.ads b/gcc/ada/exp_dbug.ads index 827f149f705..b160caf62a9 100644 --- a/gcc/ada/exp_dbug.ads +++ b/gcc/ada/exp_dbug.ads @@ -6,7 +6,7 @@ -- -- -- S p e c -- -- -- --- Copyright (C) 1996-2015, Free Software Foundation, Inc. -- +-- Copyright (C) 1996-2016, Free Software Foundation, Inc. -- -- -- -- GNAT is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- @@ -435,6 +435,21 @@ package Exp_Dbug is -- generating code, since the necessary information for computing the -- proper external name is not available in this case. + ------------------------------------- + -- Encoding for translation into C -- + ------------------------------------- + + -- In Modify_Tree_For_C mode we must add encodings to dismabiguate cases + -- where Ada block structure cannot be directly translated. These cases + -- are as follows: + + -- a) A loop variable may hide a homonym in an enclosing block + -- b) A block-local variable may hide a homonym in an enclosing block + + -- In C these constructs are not scopes and we must distinguish the names + -- explicitly. In the first case we create a qualified name with the suffix + -- 'L', in the second case with a suffix 'B'. + -------------------------------------------- -- Subprograms for Handling Qualification -- -------------------------------------------- diff --git a/gcc/ada/exp_pakd.adb b/gcc/ada/exp_pakd.adb index 0668369afa0..b4f0f0abe96 100644 --- a/gcc/ada/exp_pakd.adb +++ b/gcc/ada/exp_pakd.adb @@ -81,12 +81,6 @@ package body Exp_Pakd is -- Local Subprograms -- ----------------------- - function Compute_Number_Components - (N : Node_Id; - Typ : Entity_Id) return Node_Id; - -- Build an expression that multiplies the length of the dimensions of the - -- array, used to control array equality checks. - procedure Compute_Linear_Subscript (Atyp : Entity_Id; N : Node_Id; @@ -96,6 +90,12 @@ package body Exp_Pakd is -- Standard.Integer representing the zero-based linear subscript value. -- This expression includes any required range checks. + function Compute_Number_Components + (N : Node_Id; + Typ : Entity_Id) return Node_Id; + -- Build an expression that multiplies the length of the dimensions of the + -- array, used to control array equality checks. + procedure Convert_To_PAT_Type (Aexp : Node_Id); -- Given an expression of a packed array type, builds a corresponding -- expression whose type is the implementation type used to represent @@ -266,38 +266,6 @@ package body Exp_Pakd is return Adjusted; end Revert_Storage_Order; - ------------------------------- - -- Compute_Number_Components -- - ------------------------------- - - function Compute_Number_Components - (N : Node_Id; - Typ : Entity_Id) return Node_Id - is - Loc : constant Source_Ptr := Sloc (N); - Len_Expr : Node_Id; - - begin - Len_Expr := - Make_Attribute_Reference (Loc, - Attribute_Name => Name_Length, - Prefix => New_Occurrence_Of (Typ, Loc), - Expressions => New_List (Make_Integer_Literal (Loc, 1))); - - for J in 2 .. Number_Dimensions (Typ) loop - Len_Expr := - Make_Op_Multiply (Loc, - Left_Opnd => Len_Expr, - Right_Opnd => - Make_Attribute_Reference (Loc, - Attribute_Name => Name_Length, - Prefix => New_Occurrence_Of (Typ, Loc), - Expressions => New_List (Make_Integer_Literal (Loc, J)))); - end loop; - - return Len_Expr; - end Compute_Number_Components; - ------------------------------ -- Compute_Linear_Subscript -- ------------------------------ @@ -434,6 +402,38 @@ package body Exp_Pakd is end loop; end Compute_Linear_Subscript; + ------------------------------- + -- Compute_Number_Components -- + ------------------------------- + + function Compute_Number_Components + (N : Node_Id; + Typ : Entity_Id) return Node_Id + is + Loc : constant Source_Ptr := Sloc (N); + Len_Expr : Node_Id; + + begin + Len_Expr := + Make_Attribute_Reference (Loc, + Attribute_Name => Name_Length, + Prefix => New_Occurrence_Of (Typ, Loc), + Expressions => New_List (Make_Integer_Literal (Loc, 1))); + + for J in 2 .. Number_Dimensions (Typ) loop + Len_Expr := + Make_Op_Multiply (Loc, + Left_Opnd => Len_Expr, + Right_Opnd => + Make_Attribute_Reference (Loc, + Attribute_Name => Name_Length, + Prefix => New_Occurrence_Of (Typ, Loc), + Expressions => New_List (Make_Integer_Literal (Loc, J)))); + end loop; + + return Len_Expr; + end Compute_Number_Components; + ------------------------- -- Convert_To_PAT_Type -- ------------------------- @@ -1882,14 +1882,13 @@ package body Exp_Pakd is LLexpr := Make_Op_Multiply (Loc, - Left_Opnd => Compute_Number_Components (N, Ltyp), + Left_Opnd => Compute_Number_Components (N, Ltyp), Right_Opnd => Make_Integer_Literal (Loc, Component_Size (Ltyp))); RLexpr := Make_Op_Multiply (Loc, - Left_Opnd => Compute_Number_Components (N, Rtyp), - Right_Opnd => - Make_Integer_Literal (Loc, Component_Size (Rtyp))); + Left_Opnd => Compute_Number_Components (N, Rtyp), + Right_Opnd => Make_Integer_Literal (Loc, Component_Size (Rtyp))); -- For the modular case, we transform the comparison to: diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb index 894d7b564b3..7a28bef3b35 100644 --- a/gcc/ada/sem_ch13.adb +++ b/gcc/ada/sem_ch13.adb @@ -8646,8 +8646,8 @@ package body Sem_Ch13 is -- function at this point. elsif Nkind (Ritem) = N_Aspect_Specification - and then Present (Aspect_Rep_Item (Ritem)) - and then Scope (Typ) /= Current_Scope + and then Present (Aspect_Rep_Item (Ritem)) + and then Scope (Typ) /= Current_Scope then declare Prag : constant Node_Id := Aspect_Rep_Item (Ritem); -- 2.30.2