diff options
author | Yannick Moy <moy@adacore.com> | 2018-12-11 11:12:26 +0000 |
---|---|---|
committer | Pierre-Marie de Rodat <pmderodat@gcc.gnu.org> | 2018-12-11 11:12:26 +0000 |
commit | d71b0a9a041430612883f7f891bb25b8e21b6f2c (patch) | |
tree | c32b8439fc729f4c8dfb939fa06b43990cc92e88 /gcc/ada/sem_ch7.adb | |
parent | c13269965084ccb19233411164b52c7f187a5fb6 (diff) | |
download | gcc-d71b0a9a041430612883f7f891bb25b8e21b6f2c.zip gcc-d71b0a9a041430612883f7f891bb25b8e21b6f2c.tar.gz gcc-d71b0a9a041430612883f7f891bb25b8e21b6f2c.tar.bz2 |
[Ada] Do not expand code inside ignored ghost bodies
While ignored ghost code is not compiled into the executable, it may
lead to compilation errors when it makes use of language features
requiring runtime support that is not available in the available runtime
library. These errors are spurious, as the executable will never call
in these runtime units.
This patch deactivates the expansion of code inside ignored ghost bodies
of subprograms and packages, so that this code is still checked for
possible semantic errors, but it does not force the presence of useless
runtime units.
There is no impact on the executable produced.
2018-12-11 Yannick Moy <moy@adacore.com>
gcc/ada/
* 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.
gcc/testsuite/
* gnat.dg/ghost4.adb: New testcase.
From-SVN: r267015
Diffstat (limited to 'gcc/ada/sem_ch7.adb')
-rw-r--r-- | gcc/ada/sem_ch7.adb | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/gcc/ada/sem_ch7.adb b/gcc/ada/sem_ch7.adb index 5004517..01c2260 100644 --- a/gcc/ada/sem_ch7.adb +++ b/gcc/ada/sem_ch7.adb @@ -669,6 +669,7 @@ package body Sem_Ch7 is 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 @@ -780,6 +781,18 @@ package body Sem_Ch7 is 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. @@ -1075,6 +1088,10 @@ package body Sem_Ch7 is 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; |