[Ada] Spurious error with null Abstract_State
authorHristian Kirtchev <kirtchev@adacore.com>
Mon, 16 Jul 2018 14:11:47 +0000 (14:11 +0000)
committerPierre-Marie de Rodat <pmderodat@gcc.gnu.org>
Mon, 16 Jul 2018 14:11:47 +0000 (14:11 +0000)
This patch corrects the mechanism which ensures that a package with a null
Abstract_State does not introduce hidden state, by ignoring internal states
and variables because they do not represent the "source" hidden state.

2018-07-16  Hristian Kirtchev  <kirtchev@adacore.com>

gcc/ada/

* sem_util.adb (Check_No_Hidden_State): Ignore internally-generated
states and variables.

gcc/testsuite/

* gnat.dg/abstract_state1.adb, gnat.dg/abstract_state1.ads: New
testcase.

From-SVN: r262722

gcc/ada/ChangeLog
gcc/ada/sem_util.adb
gcc/testsuite/ChangeLog
gcc/testsuite/gnat.dg/abstract_state1.adb [new file with mode: 0644]
gcc/testsuite/gnat.dg/abstract_state1.ads [new file with mode: 0644]

index 1a14dae784e04d26ee7b3c5cb15805a4e787fbf5..9644f6f74f9d7b131585428cfe426b0c8dce1c28 100644 (file)
@@ -1,3 +1,8 @@
+2018-07-16  Hristian Kirtchev  <kirtchev@adacore.com>
+
+       * sem_util.adb (Check_No_Hidden_State): Ignore internally-generated
+       states and variables.
+
 2018-07-16  Piotr Trojanek  <trojanek@adacore.com>
 
        * sinfo.ads, sinfo.adb (Withed_Body): Remove.
index 59687f5c110da3eb35408182f62904b891a794cf..b6b939cca4e701eea90ae2e1bcb5c78dd49ea30e 100644 (file)
@@ -3228,6 +3228,13 @@ package body Sem_Util is
    begin
       pragma Assert (Ekind_In (Id, E_Abstract_State, E_Variable));
 
+      --  Nothing to do for internally-generated abstract states and variables
+      --  because they do not represent the hidden state of the source unit.
+
+      if not Comes_From_Source (Id) then
+         return;
+      end if;
+
       --  Find the proper context where the object or state appears
 
       Scop := Scope (Id);
index 89e2c79c23a6538111b5ce220cc61fa78afebd14..d1b2558a958fdbdd580be725ef452c55f92afd56 100644 (file)
@@ -1,3 +1,8 @@
+2018-07-16  Hristian Kirtchev  <kirtchev@adacore.com>
+
+       * gnat.dg/abstract_state1.adb, gnat.dg/abstract_state1.ads: New
+       testcase.
+
 2018-07-16  Hristian Kirtchev  <kirtchev@adacore.com>
 
        * gnat.dg/validity_check3.adb, gnat.dg/validity_check3.ads: New
diff --git a/gcc/testsuite/gnat.dg/abstract_state1.adb b/gcc/testsuite/gnat.dg/abstract_state1.adb
new file mode 100644 (file)
index 0000000..b5ca07a
--- /dev/null
@@ -0,0 +1,5 @@
+--  { dg-do compile }
+
+package body Abstract_State1 is
+   procedure Foo is null;
+end Abstract_State1;
diff --git a/gcc/testsuite/gnat.dg/abstract_state1.ads b/gcc/testsuite/gnat.dg/abstract_state1.ads
new file mode 100644 (file)
index 0000000..306f051
--- /dev/null
@@ -0,0 +1,24 @@
+package Abstract_State1
+  with Abstract_State => null,
+       Initializes    => null
+is
+   type Complex (B : Boolean) is tagged private;
+   type No_F is tagged private;
+   X : constant No_F;
+
+   procedure Foo;
+
+private
+   type Complex (B : Boolean) is tagged record
+      G : Integer;
+      case B is
+         when True =>
+            F : Integer;
+         when False =>
+            null;
+      end case;
+   end record;
+
+   type No_F is new Complex (False) with null record;
+   X : constant No_F := (B => False, G => 7);
+end Abstract_State1;