This patch fixes a spurious error when expanding the code for a function
that appears in a Ghost context, when return return type of the function
is unconstrainedm and the restriction No_Secondary_Stack is active.
Running this command:
gcc -c repro_main.adb
On the following sources:
with Bounded_Table;
procedure Repro_Main
is
package B is new
Bounded_Table (Element_Type => Integer, Max => 1000, Null_Elem => 0);
pragma Unreferenced (B);
begin
null;
end Repro_Main;
package body Bounded_Table is
function Model (Table : T) return Model_Type
is (Model_Type (Table.Elems (Table.Elems'First .. Table.Last)));
end Bounded_Table;
Should execute silently.
Tested on x86_64-pc-linux-gnu, committed on trunk
2019-10-10 Ed Schonberg <schonb...@adacore.com>
gcc/ada/
* exp_ch6.adb (Expand_Simple_Function_Return_Statement): If the
function to which the return statement applies is an
Ignored_Ghost_Function, do not indicate that it uses the
secondary stack when the return type is unconstrained.
--- gcc/ada/exp_ch6.adb
+++ gcc/ada/exp_ch6.adb
@@ -6895,7 +6895,12 @@ package body Exp_Ch6 is
elsif Is_Thunk (Current_Scope) and then Is_Incomplete_Type (Exptyp) then
return;
- elsif not Requires_Transient_Scope (R_Type) then
+ -- A return statement from a Ghost function does not use the secondary
+ -- stack (or any other one).
+
+ elsif not Requires_Transient_Scope (R_Type)
+ or else Is_Ignored_Ghost_Entity (Scope_Id)
+ then
-- Mutable records with variable-length components are not returned
-- on the sec-stack, so we need to make sure that the back end will