aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorEd Schonberg <schonberg@adacore.com>2015-10-23 12:51:30 +0000
committerArnaud Charlet <charlet@gcc.gnu.org>2015-10-23 14:51:30 +0200
commit241fac51c3e6a4745d28b36121702325212c3af6 (patch)
tree01791b6f975000aa2e526411d4e91cd221b8e1d0 /gcc
parent43184ab7cd9ee60b3aa12eeed66f42076537548f (diff)
downloadgcc-241fac51c3e6a4745d28b36121702325212c3af6.zip
gcc-241fac51c3e6a4745d28b36121702325212c3af6.tar.gz
gcc-241fac51c3e6a4745d28b36121702325212c3af6.tar.bz2
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
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ada/ChangeLog14
-rw-r--r--gcc/ada/exp_ch6.adb23
-rw-r--r--gcc/ada/sem_ch6.adb12
3 files changed, 43 insertions, 6 deletions
diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog
index 161c024..8bc9fb5 100644
--- a/gcc/ada/ChangeLog
+++ b/gcc/ada/ChangeLog
@@ -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>
* 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 c385a25..eb25c9b 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 8b5a9fd..30be333 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