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] Indirect calls in static elaboration model


This patch makes the static elaboration model more conservative in the case of
indirect calls, by treating Subp'Access as a call for elaboration purposes.

The following test should print 3, even when compiled with the binder switch
-p, which enables pessimistic (worst-case) elaboration order.

gnatmake -f a4 -bargs -p

Expected output:

warning: use of -p switch questionable
warning: since all units compiled with static elaboration model
 3

package a1 is
   function f return Integer;
end a1;

with a2;
package body a1 is
   function f return integer is
   begin
      return a2.f;
   end;
end a1;

package a2 is
   function f return Integer;
end a2;

package body a2 is
   function Ident (X : Integer) return Integer is
   begin
      return X;
   end;

   Var : Integer := Ident (3);

   function f return Integer is
   begin
      return Var;
   end f;
end a2;

with a1;
package a3 is
   type P is access function return Integer;
   PP : P := a1.f'Access;
   R  : Integer := PP.all;
end a3;

with a3;
with Text_IO; use Text_IO;
procedure a4 is
begin
   Put_Line (a3.R'Img);
end;

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

2012-03-15  Bob Duff  <duff@adacore.com>

	* debug.adb: Add new debug switch -gnatd.U, which disables the
	support added below, in case someone trips over a cycle, and needs
	to disable this.
	* sem_attr.adb (Analyze_Access_Attribute):
	Treat Subp'Access as a call for elaboration purposes.
	* sem_elab.ads, sem_elab.adb (Check_Elab_Call): Add support
	for Subp'Access.

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]