From 241fac51c3e6a4745d28b36121702325212c3af6 Mon Sep 17 00:00:00 2001 From: Ed Schonberg Date: Fri, 23 Oct 2015 12:51:30 +0000 Subject: [PATCH] sem_ch6.adb (Check_Missing_Return): Do not report a missing return statement on a function body constructed to... 2015-10-23 Ed Schonberg * sem_ch6.adb (Check_Missing_Return): Do not report a missing return statement on a function body constructed to complete a package body for a premature instantiation. 2015-10-23 Ed Schonberg * exp_ch6.adb (Build_Procedure_Body_Form): Replace body of original function with that of generated procedure, to simplify processing and avoid scoping problems with local declarations. (Rewrite_Function_Call_For_C): Handle properly the case of a parameterless function. From-SVN: r229249 --- gcc/ada/ChangeLog | 14 ++++++++++++++ gcc/ada/exp_ch6.adb | 23 +++++++++++++++++------ gcc/ada/sem_ch6.adb | 12 ++++++++++++ 3 files changed, 43 insertions(+), 6 deletions(-) diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index 161c024f381..8bc9fb5cdca 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,17 @@ +2015-10-23 Ed Schonberg + + * sem_ch6.adb (Check_Missing_Return): Do not report a missing + return statement on a function body constructed to complete a + package body for a premature instantiation. + +2015-10-23 Ed Schonberg + + * exp_ch6.adb (Build_Procedure_Body_Form): Replace body of + original function with that of generated procedure, to simplify + processing and avoid scoping problems with local declarations. + (Rewrite_Function_Call_For_C): Handle properly the case of a + parameterless function. + 2015-10-23 Hristian Kirtchev * a-exextr.adb, sem_ch6.adb, sem_ch13.adb: Minor reformatting. diff --git a/gcc/ada/exp_ch6.adb b/gcc/ada/exp_ch6.adb index c385a2567f5..eb25c9b332b 100644 --- a/gcc/ada/exp_ch6.adb +++ b/gcc/ada/exp_ch6.adb @@ -4962,7 +4962,8 @@ package body Exp_Ch6 is procedure Build_Procedure_Body_Form (Func_Id : Entity_Id); -- Create a procedure body which emulates the behavior of function - -- Func_Id. + -- Func_Id. This body replaces the original function body, which is + -- not needed for the C program. ---------------- -- Add_Return -- @@ -5123,7 +5124,7 @@ package body Exp_Ch6 is -- Start of processing for Build_Procedure_Body_Form begin - -- This routine performs the following expansion: + -- This routine replaces the original function body: -- function F (...) return Array_Typ is -- begin @@ -5131,23 +5132,27 @@ package body Exp_Ch6 is -- return Something; -- end F; + -- with the following: + -- procedure P (..., Result : out Array_Typ) is -- begin -- ... -- Result := Something; -- end P; - Stmts := New_Copy_List (Statements (HSS)); + Stmts := Statements (HSS); Replace_Returns (Last_Entity (Proc_Id), Stmts); - Insert_After_And_Analyze (N, + Replace (N, Make_Subprogram_Body (Loc, Specification => Copy_Subprogram_Spec (Specification (Proc_Decl)), - Declarations => New_Copy_List (Declarations (N)), + Declarations => Declarations (N), Handled_Statement_Sequence => Make_Handled_Sequence_Of_Statements (Loc, Statements => Stmts))); + + Analyze (N); end Build_Procedure_Body_Form; -- Local varaibles @@ -5491,7 +5496,7 @@ package body Exp_Ch6 is procedure Build_Procedure_Form; -- Create a procedure declaration which emulates the behavior of - -- function Subp. + -- function Subp, for SPARK_To_C. -------------------------- -- Build_Procedure_Form -- @@ -9593,6 +9598,12 @@ package body Exp_Ch6 is begin Actuals := Parameter_Associations (N); + -- Original function amy have been parameterless. + + if No (Actuals) then + Actuals := New_List; + end if; + -- If the function call is the expression of an assignment statement, -- transform the assignment into a procedure call. Generate: diff --git a/gcc/ada/sem_ch6.adb b/gcc/ada/sem_ch6.adb index 8b5a9fde918..30be33330c8 100644 --- a/gcc/ada/sem_ch6.adb +++ b/gcc/ada/sem_ch6.adb @@ -2732,6 +2732,18 @@ package body Sem_Ch6 is Set_Has_Missing_Return (Id); end if; + -- Within a premature instantiation of a package with no body, we + -- build completions of the functions therein, with a Raise + -- statement. No point in complaining about a missing return in + -- this case. + + elsif Ekind (Id) = E_Function + and then In_Instance + and then Present (Statements (HSS)) + and then Nkind (First (Statements (HSS))) = N_Raise_Program_Error + then + null; + elsif Is_Generic_Subprogram (Id) or else not Is_Machine_Code_Subprogram (Id) then -- 2.30.2