This patch "fixes" an issue where an implicit with clause generated to emulate
an implicit Elaborate[_All] pragma appears on a 'W' line in the ALI file. As a
result, the 'W' line may introduce a spurious build dependency in GPRbuild.

------------
-- Source --
------------

--  func.ads

function Func return Boolean;

--  func.adb

function Func return Boolean is begin return True; end Func;

--  gen.ads

generic
package Gen is
   procedure Force_Body;
end Gen;

--  gen.adb

with Func;

package body Gen is
   Val : constant Boolean := Func;

   procedure Force_Body is begin null; end Force_Body;
end Gen;

--  pack.ads

with Gen;

package Pack is
   package Inst is new Gen;
end Pack;

--  main.adb

with Pack;

procedure Main is begin null; end Main;

----------------------------
-- Compilation and output --
----------------------------

$ gnatmake -q main.adb
$ grep -c "Z func" pack.ali
1

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

2017-12-15  Hristian Kirtchev  <kirtc...@adacore.com>

        * sem_elab.adb (Ensure_Prior_Elaboration_Static): Mark the generated
        with clause as being implicit for an instantiation in order to
        circumvent an issue with 'W' and 'Z' line encodings in ALI files.

Index: sem_elab.adb
===================================================================
--- sem_elab.adb        (revision 255683)
+++ sem_elab.adb        (working copy)
@@ -3585,6 +3585,16 @@
          Set_Implicit_With (Clause);
          Set_Library_Unit  (Clause, Unit_Cunit);
 
+         --  The following is a kludge to satisfy a GPRbuild requirement. In
+         --  general, internal with clauses should be encoded on a 'Z' line in
+         --  ALI files, but due to an old bug, they are encoded as source with
+         --  clauses on a 'W' line. As a result, these "semi-implicit" clauses
+         --  introduce spurious build dependencies in GPRbuild. The only way to
+         --  eliminate this effect is to mark the implicit clauses as generated
+         --  for an instantiation.
+
+         Set_Implicit_With_From_Instantiation (Clause);
+
          Append_To (Items, Clause);
       end if;
 

Reply via email to