Patchwork [Ada] Elaboration checks in generic units

login
register
mail settings
Submitter Arnaud Charlet
Date June 14, 2010, 9:37 a.m.
Message ID <20100614093750.GA3937@adacore.com>
Download mbox | patch
Permalink /patch/55501/
State New
Headers show

Comments

Arnaud Charlet - June 14, 2010, 9:37 a.m.
Calls within a generic unit do not need an elaboration check. This patch fixes
a hole in the dynamic elaboration machinery, which allowed internal calls from 
a subprogram nested within a generic unit to be placed in the list of calls 
that are examined after semantic analysis, leading to crashes in units
compiled with -gnatE.

The following must compile quietly:

   gcc -c -gnatE p1.adb
---
package P1 is
  generic
  function Gen (X : Integer) return Integer;
end;
---
package body P1 is
   function Gen (X : Integer) return Integer is
      function Gen2 (X: integer) return Integer is
      begin
        return Gen (X - 1);
      end;
   begin
      if X = 0 then
          return 0;
      else
         return Gen2 (X - Gen (2));
      end if;
   end Gen;
end;

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

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

	* sem_elab.adb (Check_Internal_Call): Do not place a call appearing
	within a generic unit in the table of delayed calls.

Patch

Index: sem_elab.adb
===================================================================
--- sem_elab.adb	(revision 149925)
+++ sem_elab.adb	(working copy)
@@ -1891,6 +1891,11 @@  package body Sem_Elab is
 
       elsif In_Task_Activation then
          return;
+
+      --  Nothing to do if call is within a generic unit.
+
+      elsif Inside_A_Generic then
+         return;
       end if;
 
       --  Delay this call if we are still delaying calls