Index: sem_ch8.adb
===================================================================
--- sem_ch8.adb	(revision 194841)
+++ sem_ch8.adb	(working copy)
@@ -8531,4 +8531,21 @@
       end loop;
    end ws;
 
+   --------
+   -- we --
+   --------
+
+   procedure we (S : Entity_Id) is
+      E : Entity_Id;
+   begin
+      E := First_Entity (S);
+      while Present (E) loop
+         Write_Int (Int (E));
+         Write_Str (" === ");
+         Write_Name (Chars (E));
+         Write_Eol;
+
+         Next_Entity (E);
+      end loop;
+   end we;
 end Sem_Ch8;
Index: sem_ch8.ads
===================================================================
--- sem_ch8.ads	(revision 194841)
+++ sem_ch8.ads	(working copy)
@@ -169,4 +169,7 @@
    procedure ws;
    --  Debugging routine for use in gdb: dump all entities on scope stack
 
+   procedure we (S : Entity_Id);
+   --  Debugging routine for use in gdb: dump all entities in given scope
+
 end Sem_Ch8;
Index: exp_ch3.adb
===================================================================
--- exp_ch3.adb	(revision 194841)
+++ exp_ch3.adb	(working copy)
@@ -5315,33 +5315,38 @@
                       Subtype_Mark        => New_Occurrence_Of (Typ, Loc),
                       Name => Convert_Tag_To_Interface (Typ, Tag_Comp)));
 
-                  --  If the original entity comes from source, then mark the
-                  --  new entity as needing debug information, even though it's
-                  --  defined by a generated renaming that does not come from
-                  --  source, so that Materialize_Entity will be set on the
-                  --  entity when Debug_Renaming_Declaration is called during
-                  --  analysis.
-
-                  if Comes_From_Source (Def_Id) then
-                     Set_Debug_Info_Needed (Defining_Identifier (N));
-                  end if;
-
                   Analyze (N, Suppress => All_Checks);
 
                   --  Replace internal identifier of rewritten node by the
                   --  identifier found in the sources. We also have to exchange
                   --  entities containing their defining identifiers to ensure
                   --  the correct replacement of the object declaration by this
-                  --  object renaming declaration ---because these identifiers
+                  --  object renaming declaration because these identifiers
                   --  were previously added by Enter_Name to the current scope.
                   --  We must preserve the homonym chain of the source entity
                   --  as well. We must also preserve the kind of the entity,
-                  --  which may be a constant.
+                  --  which may be a constant. Preserve entity chain because
+                  --  itypes may have been generated already, and the full
+                  --  chain must be preserved for final freezing. Finally,
+                  --  Preserve Comes_From_Source setting, so that debugging
+                  --  and cross-referencing information is properly kept.
 
-                  Set_Chars (Defining_Identifier (N), Chars (Def_Id));
-                  Set_Homonym (Defining_Identifier (N), Homonym (Def_Id));
-                  Set_Ekind (Defining_Identifier (N), Ekind (Def_Id));
-                  Exchange_Entities (Defining_Identifier (N), Def_Id);
+                  declare
+                     New_Id    : constant Entity_Id := Defining_Identifier (N);
+                     Next_Temp : constant Entity_Id := Next_Entity (New_Id);
+                     S_Flag    : constant Boolean   :=
+                                   Comes_From_Source (Def_Id);
+
+                  begin
+                     Set_Next_Entity (New_Id, Next_Entity (Def_Id));
+                     Set_Next_Entity (Def_Id, Next_Temp);
+                     Set_Chars (Defining_Identifier (N), Chars (Def_Id));
+                     Set_Homonym (Defining_Identifier (N), Homonym (Def_Id));
+                     Set_Ekind (Defining_Identifier (N), Ekind (Def_Id));
+                     Set_Comes_From_Source (Def_Id, False);
+                     Exchange_Entities (Defining_Identifier (N), Def_Id);
+                     Set_Comes_From_Source (Def_Id, S_Flag);
+                  end;
                end;
             end if;
 
