aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArnaud Charlet <charlet@gcc.gnu.org>2016-04-21 11:54:42 +0200
committerArnaud Charlet <charlet@gcc.gnu.org>2016-04-21 11:54:42 +0200
commitf76647c2ec8c53d40d3f011d35ab2a3691eda62c (patch)
treea525bd07154a8cea385ae9cc008414a7183f1f5b
parent22a4f9d54db67a17191dfad5dfb635465489be8c (diff)
downloadgcc-f76647c2ec8c53d40d3f011d35ab2a3691eda62c.zip
gcc-f76647c2ec8c53d40d3f011d35ab2a3691eda62c.tar.gz
gcc-f76647c2ec8c53d40d3f011d35ab2a3691eda62c.tar.bz2
[multiple changes]
2016-04-21 Hristian Kirtchev <kirtchev@adacore.com> * exp_pakd.adb, sem_ch13.adb: Minor reformatting. 2016-04-21 Ed Schonberg <schonberg@adacore.com> * 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
-rw-r--r--gcc/ada/ChangeLog10
-rw-r--r--gcc/ada/exp_dbug.adb29
-rw-r--r--gcc/ada/exp_dbug.ads17
-rw-r--r--gcc/ada/exp_pakd.adb83
-rw-r--r--gcc/ada/sem_ch13.adb4
5 files changed, 98 insertions, 45 deletions
diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog
index 2747684..602116b 100644
--- a/gcc/ada/ChangeLog
+++ b/gcc/ada/ChangeLog
@@ -1,3 +1,13 @@
+2016-04-21 Hristian Kirtchev <kirtchev@adacore.com>
+
+ * exp_pakd.adb, sem_ch13.adb: Minor reformatting.
+
+2016-04-21 Ed Schonberg <schonberg@adacore.com>
+
+ * 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 <lambourg@adacore.com>
* s-soflin.adb: Initialize the Stack_Limit global variable.
diff --git a/gcc/ada/exp_dbug.adb b/gcc/ada/exp_dbug.adb
index 1f706d6..df0543d 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 827f149..b160caf 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 0668369..b4f0f0a 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 894d7b5..7a28bef 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);