diff mbox series

[Ada] Fix internal error on package instantiation and inlining

Message ID 20170907094032.GA93720@adacore.com
State New
Headers show
Series [Ada] Fix internal error on package instantiation and inlining | expand

Commit Message

Arnaud Charlet Sept. 7, 2017, 9:40 a.m. UTC
This fixes a small regression introduced by the recent improvement to the
algorithm used by Hide_Public_Entities to compute the final set of external
visible entities of a package.  Subprogram renamings not only need to be
dealt with as declaring a subprogram but also as referencing another one.

The following procedure must compile quietly with -O -gnatn:

with Q;

procedure P (I : Integer) is
begin
  if Q.Derive (I) /= I then
    raise Program_Error;
  end if;
end;
with G;

package Q is

  function Derive (I : Integer) return Integer;
  pragma Inline (Derive);

end Q;
with G;

package body Q is

  function Value (I : Integer) return Integer is
  begin
    return I;
  end;

  package My_G is new G (Integer, Value);

  function Derive (I : Integer) return Integer is
  begin
    return My_G.Compute (I);
  end;

end Q;
generic
  type T is private;
  with function Value (Arg : T) return Integer;
package G is

  function Compute (Arg : T) return Integer;
  pragma Inline (Compute);

end G;
package body G is

  function Compute (Arg : T) return Integer is
  begin
    return Value (Arg);
  end;

end G;

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

2017-09-07  Eric Botcazou  <ebotcazou@adacore.com>

	* sem_ch7.adb (Has_Referencer): For a subprogram renaming,
	also mark the renamed subprogram as referenced.
diff mbox series

Patch

Index: sem_ch7.adb
===================================================================
--- sem_ch7.adb	(revision 251835)
+++ sem_ch7.adb	(working copy)
@@ -439,6 +439,23 @@ 
                   then
                      Set_Is_Public (Decl_Id, False);
                   end if;
+
+                  --  For a subprogram renaming, if the entity is referenced,
+                  --  then so is the renamed subprogram. But there is an issue
+                  --  with generic bodies because instantiations are not done
+                  --  yet and, therefore, cannot be scanned for referencers.
+                  --  That's why we use an approximation and test that we have
+                  --  at least one subprogram referenced by an inlined body
+                  --  instead of precisely the entity of this renaming.
+
+                  if Nkind (Decl) = N_Subprogram_Renaming_Declaration
+                    and then Subprogram_Table.Get_First
+                    and then Is_Entity_Name (Name (Decl))
+                    and then Present (Entity (Name (Decl)))
+                    and then Is_Subprogram (Entity (Name (Decl)))
+                  then
+                     Subprogram_Table.Set (Entity (Name (Decl)), True);
+                  end if;
                end if;
 
                Prev (Decl);