[multiple changes]
authorArnaud Charlet <charlet@gcc.gnu.org>
Thu, 21 Apr 2016 09:54:42 +0000 (11:54 +0200)
committerArnaud Charlet <charlet@gcc.gnu.org>
Thu, 21 Apr 2016 09:54:42 +0000 (11:54 +0200)
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

gcc/ada/ChangeLog
gcc/ada/exp_dbug.adb
gcc/ada/exp_dbug.ads
gcc/ada/exp_pakd.adb
gcc/ada/sem_ch13.adb

index 27476846f1bf9369824ccf9b99fec93d7b3eaa22..602116bfbebaf40b7d3c705beca6e7dfba0fd5a8 100644 (file)
@@ -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.
index 1f706d6bca570d514d1bb757e0d315445dadeb48..df0543d4cb06fdbd66d0f8ccac43a631c617cf02 100644 (file)
@@ -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;
 
index 827f149f705d64521912e843c239a6d90cdd2c3f..b160caf62a9cda2842178629f7313bda35ebda6f 100644 (file)
@@ -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 --
    --------------------------------------------
index 0668369afa0d4ac6911f335079306ba589ae8ed7..b4f0f0abe9658a4a1e1a75c8f332e5e7d069bc5c 100644 (file)
@@ -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:
 
index 894d7b564b3d90f5ce290a644f02ac094b494bb9..7a28bef3b353d9029d762bddfc7cef4dfe0194ca 100644 (file)
@@ -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);