+2018-12-11 Yannick Moy <moy@adacore.com>
+
+ * sem_ch6.adb (Analyze_Subprogram_Body_Helper): Deactivate
+ expansion in ignored ghost subprogram body.
+ * sem_ch7.adb (Analyze_Package_Body_Helper): Deactivate
+ expansion in ignored ghost package body.
+
2018-12-11 Ed Schonberg <schonberg@adacore.com>
* exp_unst.adb (Register_Subprogram): A subprogram whose address
Saved_GM : constant Ghost_Mode_Type := Ghost_Mode;
Saved_IGR : constant Node_Id := Ignored_Ghost_Region;
+ Saved_EA : constant Boolean := Expander_Active;
Saved_ISMP : constant Boolean :=
Ignore_SPARK_Mode_Pragmas_In_Instance;
-- Save the Ghost and SPARK mode-related data to restore on exit
end if;
end if;
+ -- Deactivate expansion inside the body of ignored Ghost entities,
+ -- as this code will ultimately be ignored. This avoids requiring the
+ -- presence of run-time units which are not needed. Only do this for
+ -- user entities, as internally generated entitities might still need
+ -- to be expanded (e.g. those generated for types).
+
+ if Present (Ignored_Ghost_Region)
+ and then Comes_From_Source (Body_Id)
+ then
+ Expander_Active := False;
+ end if;
+
-- Previously we scanned the body to look for nested subprograms, and
-- rejected an inline directive if nested subprograms were present,
-- because the back-end would generate conflicting symbols for the
end if;
<<Leave>>
+ if Present (Ignored_Ghost_Region) then
+ Expander_Active := Saved_EA;
+ end if;
+
Ignore_SPARK_Mode_Pragmas_In_Instance := Saved_ISMP;
Restore_Ghost_Region (Saved_GM, Saved_IGR);
end Analyze_Subprogram_Body_Helper;
Saved_GM : constant Ghost_Mode_Type := Ghost_Mode;
Saved_IGR : constant Node_Id := Ignored_Ghost_Region;
+ Saved_EA : constant Boolean := Expander_Active;
Saved_ISMP : constant Boolean :=
Ignore_SPARK_Mode_Pragmas_In_Instance;
-- Save the Ghost and SPARK mode-related data to restore on exit
Mark_And_Set_Ghost_Body (N, Spec_Id);
+ -- Deactivate expansion inside the body of ignored Ghost entities,
+ -- as this code will ultimately be ignored. This avoids requiring the
+ -- presence of run-time units which are not needed. Only do this for
+ -- user entities, as internally generated entitities might still need
+ -- to be expanded (e.g. those generated for types).
+
+ if Present (Ignored_Ghost_Region)
+ and then Comes_From_Source (Body_Id)
+ then
+ Expander_Active := False;
+ end if;
+
-- If the body completes the initial declaration of a compilation unit
-- which is subject to pragma Elaboration_Checks, set the model of the
-- pragma because it applies to all parts of the unit.
end if;
end if;
+ if Present (Ignored_Ghost_Region) then
+ Expander_Active := Saved_EA;
+ end if;
+
Ignore_SPARK_Mode_Pragmas_In_Instance := Saved_ISMP;
Restore_Ghost_Region (Saved_GM, Saved_IGR);
end Analyze_Package_Body_Helper;
+2018-12-11 Yannick Moy <moy@adacore.com>
+
+ * gnat.dg/ghost4.adb: New testcase.
+
2018-12-11 Ed Schonberg <schonberg@adacore.com>
* gnat.dg/iter4.adb: New testcase.
--- /dev/null
+pragma Restrictions (No_Secondary_Stack);
+
+procedure Ghost4 is
+
+ procedure Dummy with Ghost is
+ function Slice (S : String) return String is
+ (S (S'First .. S'First + 3));
+
+ X : String := Slice ("hello");
+ begin
+ null;
+ end Dummy;
+begin
+ Dummy;
+end Ghost4;