From patchwork Thu Jun 17 15:24:31 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [Ada] Eliminated protected operations Date: Thu, 17 Jun 2010 05:24:31 -0000 From: Arnaud Charlet X-Patchwork-Id: 56060 Message-Id: <20100617152431.GA14142@adacore.com> To: gcc-patches@gcc.gnu.org Cc: Ed Schonberg The enclosing dynamic scope of a construct is the subprogram body that executes the construct. If the source construct appears within a protected operation, the enclosing dynamic scope is the protected subprogram body built for it. However, this body is not constructed if the protected operation has been eliminated. In that case the enclosing dynamic scope is the source subprogram, and is used only for semantic checks. 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; private end Obj; protected body Obj is procedure Hidden is begin declare I : Integer := 1; procedure Hidden1 is begin Var := Var + I; end Hidden1; begin Hidden1; end; Var := Var + 1; end Hidden; procedure Used is begin Var := Var + 1; end; procedure Unused is begin Hidden; end; end Obj; begin Obj.Used; end Test_It; --- contents of file elim.out (output of gnatelim) -- 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:14"); pragma Eliminate (Test_It, Hidden1, Source_Location => "test_it.adb:18"); Tested on x86_64-pc-linux-gnu, committed on trunk 2010-06-17 Ed Schonberg * sem_util.adb (Enclosing_Subprogram): If the called subprogram is protected, use the protected_subprogram_body only if the original subprogram has not been eliminated. Index: sem_util.adb =================================================================== --- sem_util.adb (revision 160908) +++ sem_util.adb (working copy) @@ -2549,7 +2549,12 @@ package body Sem_Util is elsif Ekind (Dynamic_Scope) = E_Task_Type then return Get_Task_Body_Procedure (Dynamic_Scope); - elsif Convention (Dynamic_Scope) = Convention_Protected then + -- No body is generated if the protected operation is eliminated + + elsif Convention (Dynamic_Scope) = Convention_Protected + and then not Is_Eliminated (Dynamic_Scope) + and then Present (Protected_Body_Subprogram (Dynamic_Scope)) + then return Protected_Body_Subprogram (Dynamic_Scope); else