]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[Ada] Fix a freezing issue
authorJavier Miranda <miranda@adacore.com>
Tue, 31 Jul 2018 09:55:26 +0000 (09:55 +0000)
committerPierre-Marie de Rodat <pmderodat@gcc.gnu.org>
Tue, 31 Jul 2018 09:55:26 +0000 (09:55 +0000)
2018-07-31  Javier Miranda  <miranda@adacore.com>

gcc/ada/

* sem.ads (Inside_Preanalysis_Without_Freezing): New global
counter.
* sem.adb (Semantics): This subprogram has now the
responsibility of resetting the counter before analyzing a unit,
and restoring its previous value before returning.
* freeze.adb (Freeze_Entity): Do not freeze if we are
preanalyzing without freezing.
* sem_res.adb (Preanalyze_And_Resolve): Set & restore
In_Preanalysis_Without_Freezing.

From-SVN: r263091

gcc/ada/ChangeLog
gcc/ada/freeze.adb
gcc/ada/sem.adb
gcc/ada/sem.ads
gcc/ada/sem_res.adb

index ef1128ff2a73ddb4371073e89b4bbc686a75f192..33ff75bf2a6ca67b09111cf4768875b4f283a6cf 100644 (file)
@@ -1,3 +1,15 @@
+2018-07-31  Javier Miranda  <miranda@adacore.com>
+
+       * sem.ads (Inside_Preanalysis_Without_Freezing): New global
+       counter.
+       * sem.adb (Semantics): This subprogram has now the
+       responsibility of resetting the counter before analyzing a unit,
+       and restoring its previous value before returning.
+       * freeze.adb (Freeze_Entity): Do not freeze if we are
+       preanalyzing without freezing.
+       * sem_res.adb (Preanalyze_And_Resolve): Set & restore
+       In_Preanalysis_Without_Freezing.
+
 2018-07-31  Ed Schonberg  <schonberg@adacore.com>
 
        * sem_ch4.adb (Traverse_Homonyms): Consider generic actuals that
index c0da0eb3ccbc686f80950aacdf0b673b9960b594..9979cbf71e1bae365ab8ca1d4305b69cd8356d2c 100644 (file)
@@ -5280,6 +5280,12 @@ package body Freeze is
          Result := No_List;
          goto Leave;
 
+      --  Do not freeze if we are preanalyzing without freezing
+
+      elsif Inside_Preanalysis_Without_Freezing > 0 then
+         Result := No_List;
+         goto Leave;
+
       elsif Ekind (E) = E_Generic_Package then
          Result := Freeze_Generic_Entities (E);
          goto Leave;
index 799d66d78ead35774dc4cb3577d5d8b2f916ef6b..2415ef8f60522322b2a729d8e97ca6588b6059e4 100644 (file)
@@ -1447,9 +1447,18 @@ package body Sem is
       --  unit. All with'ed units are analyzed with config restrictions reset
       --  and we need to restore these saved values at the end.
 
+      Save_Preanalysis_Counter : constant Nat :=
+                                   Inside_Preanalysis_Without_Freezing;
+      --  Saves the preanalysis nesting-level counter; required since we may
+      --  need to analyze a unit as a consequence of the preanalysis of an
+      --  expression without freezing (and the loaded unit must be fully
+      --  analyzed).
+
    --  Start of processing for Semantics
 
    begin
+      Inside_Preanalysis_Without_Freezing := 0;
+
       if Debug_Unit_Walk then
          if Already_Analyzed then
             Write_Str ("(done)");
@@ -1622,6 +1631,8 @@ package body Sem is
             Unit (Comp_Unit),
             Prefix => "<-- ");
       end if;
+
+      Inside_Preanalysis_Without_Freezing := Save_Preanalysis_Counter;
    end Semantics;
 
    --------
index 0d8f41d7a074ee6f503b69c4cdb0c6f1662cced3..58f3f0555389ea952feaedf963d1ecac1326f87b 100644 (file)
@@ -286,6 +286,11 @@ package Sem is
    --  freezing nodes can modify the status of this flag, any other client
    --  should regard it as read-only.
 
+   Inside_Preanalysis_Without_Freezing : Nat := 0;
+   --  Flag indicating whether we are preanalyzing an expression performing no
+   --  freezing. Non-zero means we are inside (it is actually a level counter
+   --  to deal with nested calls).
+
    Unloaded_Subunits : Boolean := False;
    --  This flag is set True if we have subunits that are not loaded. This
    --  occurs when the main unit is a subunit, and contains lower level
index 674aec4fc6b80bb873fad98943908fb689882d72..5f9f1c3911db28f8b34091f511a75b0d13205263 100644 (file)
@@ -1671,14 +1671,17 @@ package body Sem_Res is
       T             : Entity_Id;
       With_Freezing : Boolean)
    is
-      Save_Full_Analysis   : constant Boolean := Full_Analysis;
-      Save_Must_Not_Freeze : constant Boolean := Must_Not_Freeze (N);
-
+      Save_Full_Analysis     : constant Boolean := Full_Analysis;
+      Save_Must_Not_Freeze   : constant Boolean := Must_Not_Freeze (N);
+      Save_Preanalysis_Count : constant Nat :=
+                                 Inside_Preanalysis_Without_Freezing;
    begin
       pragma Assert (Nkind (N) in N_Subexpr);
 
       if not With_Freezing then
          Set_Must_Not_Freeze (N);
+         Inside_Preanalysis_Without_Freezing :=
+           Inside_Preanalysis_Without_Freezing + 1;
       end if;
 
       Full_Analysis := False;
@@ -1708,6 +1711,14 @@ package body Sem_Res is
       Expander_Mode_Restore;
       Full_Analysis := Save_Full_Analysis;
       Set_Must_Not_Freeze (N, Save_Must_Not_Freeze);
+
+      if not With_Freezing then
+         Inside_Preanalysis_Without_Freezing :=
+           Inside_Preanalysis_Without_Freezing - 1;
+      end if;
+
+      pragma Assert
+        (Inside_Preanalysis_Without_Freezing = Save_Preanalysis_Count);
    end Preanalyze_And_Resolve;
 
    ----------------------------