[Ada] Pragma Eliminated applied to internal protected subprograms

Submitted by Arnaud Charlet on June 17, 2010, 1 p.m.


Message ID 20100617130054.GA28080@adacore.com
State New
Headers show

Commit Message

Arnaud Charlet June 17, 2010, 1 p.m.
If a protected operation has been eliminated, an internal call to it from
another protected operation (that is itself eliminated) must not be expanded,
because the corresponding body has not been constructed.

The following must compile quietly:

gnatmake -f -gnatec=elim.out test_it.adb

procedure Test_It is

   Var : Integer := 1;

   protected Obj is
      procedure Used;
      procedure Unused;
   end Obj;

   protected body Obj is
      procedure Hidden is
         Var := Var + 1;
      end Hidden;

      procedure Used is
         Var := Var + 1;

      procedure Unused is

   end Obj;

end Test_It;
file elim.out:
--  List of unused entities to be placed in gnat.adc.  --
pragma Eliminate (Test_It, Unused, Source_Location => "test_it.adb:7");
pragma Eliminate (Test_It, Hidden, Source_Location => "test_it.adb:12");

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

2010-06-17  Ed Schonberg  <schonberg@adacore.com>

	* exp_ch6.adb (Expand_Call): Do not expand a call to an internal
	protected operation if the subprogram has been eliminated.

Patch hide | download patch | download mbox

Index: exp_ch6.adb
--- exp_ch6.adb	(revision 160905)
+++ exp_ch6.adb	(working copy)
@@ -3095,12 +3095,14 @@  package body Exp_Ch6 is
       --  In Ada 2005, this may be an indirect call to an access parameter that
       --  is an access_to_subprogram. In that case the anonymous type has a
       --  scope that is a protected operation, but the call is a regular one.
+      --  In either case do not expand call if subprogram is eliminated.
       Scop := Scope (Subp);
       if Nkind (N) /= N_Entry_Call_Statement
         and then Is_Protected_Type (Scop)
         and then Ekind (Subp) /= E_Subprogram_Type
+        and then not Is_Eliminated (Subp)
          --  If the call is an internal one, it is rewritten as a call to the
          --  corresponding unprotected subprogram.