This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Ada] Stubs that complete generic subprogram do have a "prior declaration"


The intuition behind the Is_Subprogram_Stub_Without_Prior_Declaration
utility routine is to detect stubs that act as subprogram declarations
and False on stubs that act as completions. This behaviour is now fixed
for stubs that correspond to generic subprogram declarations.

This patch affects a routine that is only used in GNATprove, so no
frontend test provided. An example where the result changed from True to
False is:

-----------
-- p.ads --
-----------

package P is
   generic
   procedure Proc;
end P;

-----------
-- p.adb --
-----------

package body P is
   procedure Proc is separate; -- now we return False for this stub
end P;

----------------
-- p-proc.adb --
----------------

separate (P)
procedure Proc is
begin
   null;
end;

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

2018-12-11  Piotr Trojanek  <trojanek@adacore.com>

gcc/ada/

	* sem_util.adb (Is_Subprogram_Stub_Without_Prior_Declaration):
	Return False on stubs that complete a generic subprogram.
	* sem_util.ads: Update corresponding comment.
--- gcc/ada/sem_util.adb
+++ gcc/ada/sem_util.adb
@@ -17471,12 +17471,30 @@ package body Sem_Util is
      (N : Node_Id) return Boolean
    is
    begin
-      --  A subprogram stub without prior declaration serves as declaration for
-      --  the actual subprogram body. As such, it has an attached defining
-      --  entity of E_[Generic_]Function or E_[Generic_]Procedure.
+      pragma Assert (Nkind (N) = N_Subprogram_Body_Stub);
 
-      return Nkind (N) = N_Subprogram_Body_Stub
-        and then Ekind (Defining_Entity (N)) /= E_Subprogram_Body;
+      case Ekind (Defining_Entity (N)) is
+
+         --  A subprogram stub without prior declaration serves as declaration
+         --  for the actual subprogram body. As such, it has an attached
+         --  defining entity of E_Function or E_Procedure.
+
+         when E_Function
+            | E_Procedure
+         =>
+            return True;
+
+         --  Otherwise, it is completes a [generic] subprogram declaration
+
+         when E_Generic_Function
+            | E_Generic_Procedure
+            | E_Subprogram_Body
+         =>
+            return False;
+
+         when others =>
+            raise Program_Error;
+      end case;
    end Is_Subprogram_Stub_Without_Prior_Declaration;
 
    ---------------------------

--- gcc/ada/sem_util.ads
+++ gcc/ada/sem_util.ads
@@ -2001,8 +2001,8 @@ package Sem_Util is
 
    function Is_Subprogram_Stub_Without_Prior_Declaration
      (N : Node_Id) return Boolean;
-   --  Return True if N is a subprogram stub with no prior subprogram
-   --  declaration.
+   --  Given an N_Subprogram_Body_Stub node N, return True if N is a subprogram
+   --  stub with no prior subprogram declaration.
 
    function Is_Suitable_Primitive (Subp_Id : Entity_Id) return Boolean;
    --  Determine whether arbitrary subprogram Subp_Id may act as a primitive of


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]