This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Ada] Fix bug in handling of renaming


Tested on i686-linux, committed on trunk 

When returning a stabilized expression for a renamed entity, we must
and do expand possible SAVE_EXPRs at the renaming definition point since
the returned expression might be used in arbitrary conditional branches.

We were also doing this for the initializing expression of renaming
pointers, which was useless and causing damage when the stabilization
of this expression failed, for instance because of a function call.

Gigi for GCC 4 cured this by wrapping the expression in an outer SAVE_EXPR.
Gigi for GCC 3.4 did not do this and was consequently miscompiling the
testcase below. The change done here mirrors what was eventually done for
the GCC 3.4. This is useful for consistency purposes, and for documentation
purposes as well since a fair amount of comments are added along the way.

The code below is expected to compile and run silently.

procedure P is

   type Position_Type is record
      X, Y, Z : Integer;
   end record;

   N_Calls_To_Reference_Position : Natural := 0;

   function Reference_Position return Position_Type is
      Origin : constant Position_Type := (0, 0, 0);
   begin
      N_Calls_To_Reference_Position := N_Calls_To_Reference_Position + 1;
      return Origin;
   end;

   procedure Initialize (Position : out Position_Type) is
      Default_Position  : Position_Type renames Reference_Position;
   begin
      Position := Default_Position;
   end;

   My_Position : Position_Type;
begin
   Initialize (My_Position);

   if N_Calls_To_Reference_Position /= 1 then
      raise Program_Error;
   end if;
end;

2005-12-05  Olivier Hainque  <hainque@adacore.com>

	* decl.c (gnat_to_gnu_entity, renaming object case): Don't early expand
	pointer initialization values. Make a SAVE_EXPR instead. Add comments
	about the use and expansion of SAVE_EXPRs in the various possible
	renaming handling cases.
	(components_to_record, compare_field_bitpos): Sort by DECL_UID, not by
	abusing DECL_FCONTEXT.

Attachment: difs.6
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]