From f3e0577c2a2d3463ec8e05ec187ed7ad4f906159 Mon Sep 17 00:00:00 2001 From: Piotr Trojanek Date: Tue, 11 Dec 2018 11:10:22 +0000 Subject: [PATCH] [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; 2018-12-11 Piotr Trojanek 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. From-SVN: r266992 --- gcc/ada/ChangeLog | 6 ++++++ gcc/ada/sem_util.adb | 28 +++++++++++++++++++++++----- gcc/ada/sem_util.ads | 4 ++-- 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index 827ac09..8e2f54c 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,9 @@ +2018-12-11 Piotr Trojanek + + * sem_util.adb (Is_Subprogram_Stub_Without_Prior_Declaration): + Return False on stubs that complete a generic subprogram. + * sem_util.ads: Update corresponding comment. + 2018-12-11 Ed Schonberg * sem_ch4.adb (Analyze_Allocator): In GNATprove mode build a diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb index c5a1944..120f101 100644 --- a/gcc/ada/sem_util.adb +++ b/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; --------------------------- diff --git a/gcc/ada/sem_util.ads b/gcc/ada/sem_util.ads index b287946..39bb01f 100644 --- a/gcc/ada/sem_util.ads +++ b/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 -- 2.7.4