Commit 93bc357b by Hristian Kirtchev Committed by Pierre-Marie de Rodat

[Ada] Spurious error with null Abstract_State

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
parent 7da8b07f
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> 2018-07-16 Piotr Trojanek <trojanek@adacore.com>
* sinfo.ads, sinfo.adb (Withed_Body): Remove. * sinfo.ads, sinfo.adb (Withed_Body): Remove.
......
...@@ -3228,6 +3228,13 @@ package body Sem_Util is ...@@ -3228,6 +3228,13 @@ package body Sem_Util is
begin begin
pragma Assert (Ekind_In (Id, E_Abstract_State, E_Variable)); 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 -- Find the proper context where the object or state appears
Scop := Scope (Id); Scop := Scope (Id);
......
2018-07-16 Hristian Kirtchev <kirtchev@adacore.com> 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 * gnat.dg/validity_check3.adb, gnat.dg/validity_check3.ads: New
testcase. testcase.
......
-- { dg-do compile }
package body Abstract_State1 is
procedure Foo is null;
end Abstract_State1;
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;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment