This is the mail archive of the 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] Elaboration of expressions in address clauses

If an object has an address clause, we defer its freeze point because a
subsequent Import pragma for it may affect its elaboration. However, the
address expression itself must not be deferred because it may have side-effects
and this must appear at the proper place in the elaboration code. This patch
creates a constant declaration for the expression in an address clause whenever
this is legal, so that this expression is  elaborated where it appears, and not
at the freeze point of the object to which it applies.

The following must compile and execute quietly:

with Pack; use Pack;
procedure Check_Init is
   if not Done then raise Program_Error; end if;
with System;
package Addr is
   function Find_Place return System.Address;
   function Report return Boolean;
end Addr;
package body Addr is
   Anchor : Integer := 0;
   function Find_Place return System.Address is
      Anchor := 111;
      return Anchor'Address; 
   end Find_Place;

   function Report return Boolean is
      return Anchor = 111;
end Addr;
with Addr; use Addr;
package Pack is
   Var1 : Integer;
   for Var1'address use Find_Place;
   Done : Boolean := Report;
   Var2 : Integer;

Tested on x86_64-pc-linux-gnu, committed on trunk

2010-08-05  Ed Schonberg  <>

	*, exp_util.adb (Needs_Constant_Address): New predicate to
	determine whether the expression in an address clause for an
	initialized object must be constant. Code moved from freeze.adb.
	(Remove_Side_Effects): When the temporary is initialized with a
	reference, indicate that the temporary is a constant as done in all
	other cases.
	* freeze.adb (Check_Address_Clause): use Needs_Constant_Address.
	* exp_ch13.adb (Expand_N_Attribute_Definition_Clause, case 'Address):
	If object does not need a constant address, remove side effects from
	address expression, so it is elaborated at the point of the address
	clause and not at the freeze point of the object, so that elaboration
	order is respected.

Attachment: difs
Description: Text document

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