diff mbox

[Ada] New debug switch -gnatd.o

Message ID 20160622100036.GA26913@adacore.com
State New
Headers show

Commit Message

Arnaud Charlet June 22, 2016, 10 a.m. UTC
This patch causes -gnatd.o to choose a more conservative elaboration order.
The following test should compile and run quietly.

gnatmake -q -f -gnatd.o -g -O0 elab_indirect_2-main -bargs -p -ws

with Elab_Indirect;
with Elab_Indirect.Child;
package body Elab_Indirect_2 is

   procedure P is
   begin
      null;
   end P;

   procedure Process_Line (Line : String) is
   begin
      Elab_Indirect.Child.Child_Proc;
   end Process_Line;

   procedure Q is
   begin
      Elab_Indirect.Process_Lines (Process_Line'Access);
   end Q;

begin
   Q;
end Elab_Indirect_2;
package Elab_Indirect_2 is

   procedure P;

end Elab_Indirect_2;
procedure Elab_Indirect_2.Main is
begin
   null;
end Elab_Indirect_2.Main;
package body Elab_Indirect is

   procedure Process_Lines
     (Process_Line : access procedure (Line : String)) is
   begin
      Process_Line ("Hello");
   end Process_Lines;

end Elab_Indirect;
package Elab_Indirect is

   procedure Process_Lines
     (Process_Line : access procedure (Line : String));

end Elab_Indirect;
with Text_IO; use Text_IO;
package body Elab_Indirect.Child is

   type String_Ref is access all String;
   Var : String_Ref := new String'("Hello world");

   procedure Child_Proc is
   begin
      if Var.all /= "Hello world" then
         raise Program_Error;
      end if;
   end Child_Proc;

end Elab_Indirect.Child;
package Elab_Indirect.Child is

   procedure Child_Proc;

end Elab_Indirect.Child;

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

2016-06-22  Bob Duff  <duff@adacore.com>

	* debug.adb: Document debug switch -gnatd.o.
	* sem_elab.adb (Check_Internal_Call): Debug switch -gnatd.o
	now causes a more conservative treatment of indirect calls,
	treating P'Access as a call to P in more cases. We Can't make
	this the default, because it breaks common idioms, for example
	the soft links.
	* sem_util.adb: Add an Assert.
diff mbox

Patch

Index: debug.adb
===================================================================
--- debug.adb	(revision 237680)
+++ debug.adb	(working copy)
@@ -105,7 +105,7 @@ 
    --  d.l  Use Ada 95 semantics for limited function returns
    --  d.m  For -gnatl, print full source only for main unit
    --  d.n  Print source file names
-   --  d.o
+   --  d.o  Conservative elaboration order for indirect calls
    --  d.p
    --  d.q
    --  d.r  Enable OK_To_Reorder_Components in non-variant records
@@ -556,6 +556,9 @@ 
    --       compiler has a bug -- these are the files that need to be included
    --       in a bug report.
 
+   --  d.o  Conservative elaboration order for indirect calls. This causes
+   --       P'Access to be treated as a call in more cases.
+
    --  d.r  Forces the flag OK_To_Reorder_Components to be set in all record
    --       base types that have no discriminants.
 
Index: sem_util.adb
===================================================================
--- sem_util.adb	(revision 237680)
+++ sem_util.adb	(working copy)
@@ -6314,6 +6314,7 @@ 
          Encl_Unit := Library_Unit (Encl_Unit);
       end loop;
 
+      pragma Assert (Nkind (Encl_Unit) = N_Compilation_Unit);
       return Encl_Unit;
    end Enclosing_Lib_Unit_Node;
 
Index: sem_elab.adb
===================================================================
--- sem_elab.adb	(revision 237680)
+++ sem_elab.adb	(working copy)
@@ -2139,7 +2139,8 @@ 
       --  node comes from source.
 
       if Nkind (N) = N_Attribute_Reference
-        and then (not Warn_On_Elab_Access or else not Comes_From_Source (N))
+        and then ((not Warn_On_Elab_Access and then not Debug_Flag_Dot_O)
+                    or else not Comes_From_Source (N))
       then
          return;