2015-10-23 Ed Schonberg <schonberg@adacore.com>
authorcharlet <charlet@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 23 Oct 2015 12:51:30 +0000 (12:51 +0000)
committercharlet <charlet@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 23 Oct 2015 12:51:30 +0000 (12:51 +0000)
* 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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@229249 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ada/ChangeLog
gcc/ada/exp_ch6.adb
gcc/ada/sem_ch6.adb

index 161c024..8bc9fb5 100644 (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>
 
        * a-exextr.adb, sem_ch6.adb, sem_ch13.adb: Minor reformatting.
index c385a25..eb25c9b 100644 (file)
@@ -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:
 
index 8b5a9fd..30be333 100644 (file)
@@ -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