sem_ch6.adb (Check_Missing_Return): Do not report a missing return statement on a function body constructed to...

2015-10-23  Ed Schonberg  <schonberg@adacore.com>

	* 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  <schonberg@adacore.com>

	* 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
This commit is contained in:
Ed Schonberg 2015-10-23 12:51:30 +00:00 committed by Arnaud Charlet
parent 43184ab7cd
commit 241fac51c3
3 changed files with 43 additions and 6 deletions

View File

@ -1,3 +1,17 @@
2015-10-23 Ed Schonberg <schonberg@adacore.com>
* 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 <schonberg@adacore.com>
* 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 <kirtchev@adacore.com> 2015-10-23 Hristian Kirtchev <kirtchev@adacore.com>
* a-exextr.adb, sem_ch6.adb, sem_ch13.adb: Minor reformatting. * a-exextr.adb, sem_ch6.adb, sem_ch13.adb: Minor reformatting.

View File

@ -4962,7 +4962,8 @@ package body Exp_Ch6 is
procedure Build_Procedure_Body_Form (Func_Id : Entity_Id); procedure Build_Procedure_Body_Form (Func_Id : Entity_Id);
-- Create a procedure body which emulates the behavior of function -- 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 -- -- Add_Return --
@ -5123,7 +5124,7 @@ package body Exp_Ch6 is
-- Start of processing for Build_Procedure_Body_Form -- Start of processing for Build_Procedure_Body_Form
begin begin
-- This routine performs the following expansion: -- This routine replaces the original function body:
-- function F (...) return Array_Typ is -- function F (...) return Array_Typ is
-- begin -- begin
@ -5131,23 +5132,27 @@ package body Exp_Ch6 is
-- return Something; -- return Something;
-- end F; -- end F;
-- with the following:
-- procedure P (..., Result : out Array_Typ) is -- procedure P (..., Result : out Array_Typ) is
-- begin -- begin
-- ... -- ...
-- Result := Something; -- Result := Something;
-- end P; -- end P;
Stmts := New_Copy_List (Statements (HSS)); Stmts := Statements (HSS);
Replace_Returns (Last_Entity (Proc_Id), Stmts); Replace_Returns (Last_Entity (Proc_Id), Stmts);
Insert_After_And_Analyze (N, Replace (N,
Make_Subprogram_Body (Loc, Make_Subprogram_Body (Loc,
Specification => Specification =>
Copy_Subprogram_Spec (Specification (Proc_Decl)), Copy_Subprogram_Spec (Specification (Proc_Decl)),
Declarations => New_Copy_List (Declarations (N)), Declarations => Declarations (N),
Handled_Statement_Sequence => Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc, Make_Handled_Sequence_Of_Statements (Loc,
Statements => Stmts))); Statements => Stmts)));
Analyze (N);
end Build_Procedure_Body_Form; end Build_Procedure_Body_Form;
-- Local varaibles -- Local varaibles
@ -5491,7 +5496,7 @@ package body Exp_Ch6 is
procedure Build_Procedure_Form; procedure Build_Procedure_Form;
-- Create a procedure declaration which emulates the behavior of -- Create a procedure declaration which emulates the behavior of
-- function Subp. -- function Subp, for SPARK_To_C.
-------------------------- --------------------------
-- Build_Procedure_Form -- -- Build_Procedure_Form --
@ -9593,6 +9598,12 @@ package body Exp_Ch6 is
begin begin
Actuals := Parameter_Associations (N); 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, -- If the function call is the expression of an assignment statement,
-- transform the assignment into a procedure call. Generate: -- transform the assignment into a procedure call. Generate:

View File

@ -2732,6 +2732,18 @@ package body Sem_Ch6 is
Set_Has_Missing_Return (Id); Set_Has_Missing_Return (Id);
end if; 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) elsif Is_Generic_Subprogram (Id)
or else not Is_Machine_Code_Subprogram (Id) or else not Is_Machine_Code_Subprogram (Id)
then then