Commit 2d9a8c0b by Maroua Maalej Committed by Pierre-Marie de Rodat

[Ada] SPARK: fix a bug related to loop exit environment

2018-09-26  Maroua Maalej  <maalej@adacore.com>

gcc/ada/

	* sem_spark.adb (Check_Loop_Statement): Fix a bug related to
	loop exit environment.
	(Check_Statement): fixing a bug when comparing the source and
	target in an assignment statement.

From-SVN: r264631
parent 1a409f80
2018-09-26 Maroua Maalej <maalej@adacore.com>
* sem_spark.adb (Check_Loop_Statement): Fix a bug related to
loop exit environment.
(Check_Statement): fixing a bug when comparing the source and
target in an assignment statement.
2018-09-26 Hristian Kirtchev <kirtchev@adacore.com> 2018-09-26 Hristian Kirtchev <kirtchev@adacore.com>
* sem_ch12.adb (Instantiate_Package_Body): Capture and restore * sem_ch12.adb (Instantiate_Package_Body): Capture and restore
......
...@@ -866,8 +866,17 @@ package body Sem_SPARK is ...@@ -866,8 +866,17 @@ package body Sem_SPARK is
Target_Ent : constant Entity_Id := Defining_Identifier (Decl); Target_Ent : constant Entity_Id := Defining_Identifier (Decl);
Target_Typ : Node_Id renames Etype (Target_Ent); Target_Typ : Node_Id renames Etype (Target_Ent);
Target_View_Typ : Entity_Id;
Check : Boolean := True; Check : Boolean := True;
begin begin
if Present (Full_View (Target_Typ)) then
Target_View_Typ := Full_View (Target_Typ);
else
Target_View_Typ := Target_Typ;
end if;
case N_Declaration'(Nkind (Decl)) is case N_Declaration'(Nkind (Decl)) is
when N_Full_Type_Declaration => when N_Full_Type_Declaration =>
if not Has_Ownership_Aspect_True (Target_Ent, "type declaration") if not Has_Ownership_Aspect_True (Target_Ent, "type declaration")
...@@ -878,7 +887,7 @@ package body Sem_SPARK is ...@@ -878,7 +887,7 @@ package body Sem_SPARK is
-- ??? What about component declarations with defaults. -- ??? What about component declarations with defaults.
when N_Object_Declaration => when N_Object_Declaration =>
if (Is_Access_Type (Target_Typ) if (Is_Access_Type (Target_View_Typ)
or else Is_Deep (Target_Typ)) or else Is_Deep (Target_Typ))
and then not Has_Ownership_Aspect_True and then not Has_Ownership_Aspect_True
(Target_Ent, "Object declaration ") (Target_Ent, "Object declaration ")
...@@ -886,7 +895,7 @@ package body Sem_SPARK is ...@@ -886,7 +895,7 @@ package body Sem_SPARK is
Check := False; Check := False;
end if; end if;
if Is_Anonymous_Access_Type (Target_Typ) if Is_Anonymous_Access_Type (Target_View_Typ)
and then not Present (Expression (Decl)) and then not Present (Expression (Decl))
then then
...@@ -905,7 +914,7 @@ package body Sem_SPARK is ...@@ -905,7 +914,7 @@ package body Sem_SPARK is
-- Initializing object, access type -- Initializing object, access type
if Is_Access_Type (Target_Typ) then if Is_Access_Type (Target_View_Typ) then
-- Initializing object, constant access type -- Initializing object, constant access type
...@@ -913,7 +922,7 @@ package body Sem_SPARK is ...@@ -913,7 +922,7 @@ package body Sem_SPARK is
-- Initializing object, constant access to variable type -- Initializing object, constant access to variable type
if not Is_Access_Constant (Target_Typ) then if not Is_Access_Constant (Target_View_Typ) then
Current_Checking_Mode := Borrow; Current_Checking_Mode := Borrow;
-- Initializing object, constant access to constant type -- Initializing object, constant access to constant type
...@@ -921,7 +930,7 @@ package body Sem_SPARK is ...@@ -921,7 +930,7 @@ package body Sem_SPARK is
-- Initializing object, -- Initializing object,
-- constant access to constant anonymous type. -- constant access to constant anonymous type.
elsif Is_Anonymous_Access_Type (Target_Typ) then elsif Is_Anonymous_Access_Type (Target_View_Typ) then
-- This is an object declaration so the target -- This is an object declaration so the target
-- of the assignement is a stand-alone object. -- of the assignement is a stand-alone object.
...@@ -943,12 +952,12 @@ package body Sem_SPARK is ...@@ -943,12 +952,12 @@ package body Sem_SPARK is
else else
-- Initializing object, variable access to variable type -- Initializing object, variable access to variable type
if not Is_Access_Constant (Target_Typ) then if not Is_Access_Constant (Target_View_Typ) then
-- Initializing object, variable named access to -- Initializing object, variable named access to
-- variable type. -- variable type.
if not Is_Anonymous_Access_Type (Target_Typ) then if not Is_Anonymous_Access_Type (Target_View_Typ) then
Current_Checking_Mode := Move; Current_Checking_Mode := Move;
-- Initializing object, variable anonymous access to -- Initializing object, variable anonymous access to
...@@ -968,7 +977,7 @@ package body Sem_SPARK is ...@@ -968,7 +977,7 @@ package body Sem_SPARK is
-- Initializing object, -- Initializing object,
-- variable named access to constant type. -- variable named access to constant type.
if not Is_Anonymous_Access_Type (Target_Typ) then if not Is_Anonymous_Access_Type (Target_View_Typ) then
Error_Msg_N ("assignment not allowed, Ownership " Error_Msg_N ("assignment not allowed, Ownership "
& "Aspect False (Anonymous Access " & "Aspect False (Anonymous Access "
& "Object)", Decl); & "Object)", Decl);
...@@ -1201,6 +1210,7 @@ package body Sem_SPARK is ...@@ -1201,6 +1210,7 @@ package body Sem_SPARK is
Check_Node (Right_Opnd (Expr)); Check_Node (Right_Opnd (Expr));
-- Forbid all deep expressions for Attribute ??? -- Forbid all deep expressions for Attribute ???
-- What about generics? (formal parameters).
when N_Attribute_Reference => when N_Attribute_Reference =>
case Attribute_Name (Expr) is case Attribute_Name (Expr) is
...@@ -1690,12 +1700,12 @@ package body Sem_SPARK is ...@@ -1690,12 +1700,12 @@ package body Sem_SPARK is
if Exit_Env /= null then if Exit_Env /= null then
Copy_Env (From => Exit_Env.all, To => Current_Perm_Env); Copy_Env (From => Exit_Env.all, To => Current_Perm_Env);
Free_Env (Loop_Env.all);
Free_Env (Exit_Env.all);
else else
Copy_Env (From => Loop_Env.all, To => Current_Perm_Env); Copy_Env (From => Loop_Env.all, To => Current_Perm_Env);
end if;
Free_Env (Loop_Env.all); Free_Env (Loop_Env.all);
Free_Env (Exit_Env.all); end if;
end; end;
end Check_Loop_Statement; end Check_Loop_Statement;
...@@ -2247,7 +2257,8 @@ package body Sem_SPARK is ...@@ -2247,7 +2257,8 @@ package body Sem_SPARK is
-- Target /= source root -- Target /= source root
if Nkind_In (Expression (Stmt), N_Allocator, N_Null) if Nkind_In (Expression (Stmt), N_Allocator, N_Null)
or else St_Name /= Get_Root (Expression (Stmt)) or else Entity (St_Name) /=
Entity (Get_Root (Expression (Stmt)))
then then
Error_Msg_N ("assignment not allowed, anonymous " Error_Msg_N ("assignment not allowed, anonymous "
& "access Object with Different Root", & "access Object with Different Root",
...@@ -2307,7 +2318,10 @@ package body Sem_SPARK is ...@@ -2307,7 +2318,10 @@ package body Sem_SPARK is
-- Assigning to composite (deep) type. -- Assigning to composite (deep) type.
elsif Is_Deep (Ty_St_Name) then elsif Is_Deep (Ty_St_Name) then
if Ekind (Ty_St_Name) = E_Record_Type then if Ekind_In (Ty_St_Name,
E_Record_Type,
E_Record_Subtype)
then
declare declare
Elmt : Entity_Id := Elmt : Entity_Id :=
First_Component_Or_Discriminant (Ty_St_Name); First_Component_Or_Discriminant (Ty_St_Name);
...@@ -2333,6 +2347,13 @@ package body Sem_SPARK is ...@@ -2333,6 +2347,13 @@ package body Sem_SPARK is
if Check then if Check then
Current_Checking_Mode := Move; Current_Checking_Mode := Move;
end if; end if;
elsif Ekind_In (Ty_St_Name,
E_Array_Type,
E_Array_Subtype)
and then Check
then
Current_Checking_Mode := Move;
end if; end if;
-- Now handle legality rules of using a borrowed, observed, -- Now handle legality rules of using a borrowed, observed,
...@@ -4452,8 +4473,15 @@ package body Sem_SPARK is ...@@ -4452,8 +4473,15 @@ package body Sem_SPARK is
Global_Var : Boolean) Global_Var : Boolean)
is is
Elem : Perm_Tree_Access; Elem : Perm_Tree_Access;
View_Typ : Entity_Id;
begin begin
if Present (Full_View (Etype (Id))) then
View_Typ := Full_View (Etype (Id));
else
View_Typ := Etype (Id);
end if;
Elem := new Perm_Tree_Wrapper' Elem := new Perm_Tree_Wrapper'
(Tree => (Tree =>
(Kind => Entire_Object, (Kind => Entire_Object,
...@@ -4481,16 +4509,16 @@ package body Sem_SPARK is ...@@ -4481,16 +4509,16 @@ package body Sem_SPARK is
-- a function, and a borrow operation for a procedure. -- a function, and a borrow operation for a procedure.
if not Global_Var then if not Global_Var then
if (Is_Access_Type (Etype (Id)) if (Is_Access_Type (View_Typ)
and then Is_Access_Constant (Etype (Id)) and then Is_Access_Constant (View_Typ)
and then Is_Anonymous_Access_Type (Etype (Id))) and then Is_Anonymous_Access_Type (View_Typ))
or else or else
(Is_Access_Type (Etype (Id)) (Is_Access_Type (View_Typ)
and then Ekind (Scope (Id)) = E_Function) and then Ekind (Scope (Id)) = E_Function)
or else or else
(not Is_Access_Type (Etype (Id)) (not Is_Access_Type (View_Typ)
and then Is_Deep (Etype (Id)) and then Is_Deep (View_Typ)
and then not Is_Anonymous_Access_Type (Etype (Id))) and then not Is_Anonymous_Access_Type (View_Typ))
then then
Elem.all.Tree.Permission := Observed; Elem.all.Tree.Permission := Observed;
Elem.all.Tree.Children_Permission := Observed; Elem.all.Tree.Children_Permission := Observed;
......
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