Commit 18431dc5 by Arnaud Charlet

[multiple changes]

2016-04-20  Hristian Kirtchev  <kirtchev@adacore.com>

	* exp_ch4.adb (Expand_Allocator_Expression): Ensure that the
	tag assignment and adjustment preceed the accessibility check.
	* exp_ch7.adb (Is_Subprogram_Call): Reimplemented.

2016-04-20  Hristian Kirtchev  <kirtchev@adacore.com>

	* exp_prag.adb (Expand_Attributes): Ensure that
	the temporary used to capture the value of attribute 'Old's
	prefix is properly initialized.

2016-04-20  Javier Miranda  <miranda@adacore.com>

	* exp_unst.ads, exp_unst.adb (Get_Level, Subp_Index): Moved to library
	level.

From-SVN: r235258
parent dfbc6cbe
2016-04-20 Hristian Kirtchev <kirtchev@adacore.com>
* exp_ch4.adb (Expand_Allocator_Expression): Ensure that the
tag assignment and adjustment preceed the accessibility check.
* exp_ch7.adb (Is_Subprogram_Call): Reimplemented.
2016-04-20 Hristian Kirtchev <kirtchev@adacore.com>
* exp_prag.adb (Expand_Attributes): Ensure that
the temporary used to capture the value of attribute 'Old's
prefix is properly initialized.
2016-04-20 Javier Miranda <miranda@adacore.com>
* exp_unst.ads, exp_unst.adb (Get_Level, Subp_Index): Moved to library
level.
2016-04-20 Arnaud Charlet <charlet@adacore.com> 2016-04-20 Arnaud Charlet <charlet@adacore.com>
* sem_ch9.adb (Analyze_Task_Type_Declaration): Shut down warning * sem_ch9.adb (Analyze_Task_Type_Declaration): Shut down warning
......
...@@ -1182,8 +1182,6 @@ package body Exp_Ch4 is ...@@ -1182,8 +1182,6 @@ package body Exp_Ch4 is
end; end;
end if; end if;
Apply_Accessibility_Check (Temp);
-- Generate the tag assignment -- Generate the tag assignment
-- Suppress the tag assignment for VM targets because VM tags are -- Suppress the tag assignment for VM targets because VM tags are
...@@ -1241,34 +1239,36 @@ package body Exp_Ch4 is ...@@ -1241,34 +1239,36 @@ package body Exp_Ch4 is
Insert_Action (N, Tag_Assign); Insert_Action (N, Tag_Assign);
end if; end if;
if Needs_Finalization (DesigT) and then Needs_Finalization (T) then -- Generate an Adjust call if the object will be moved. In Ada 2005,
-- the object may be inherently limited, in which case there is no
-- Adjust procedure, and the object is built in place. In Ada 95, the
-- object can be limited but not inherently limited if this allocator
-- came from a return statement (we're allocating the result on the
-- secondary stack). In that case, the object will be moved, so we do
-- want to Adjust.
-- Generate an Adjust call if the object will be moved. In Ada if Needs_Finalization (DesigT)
-- 2005, the object may be inherently limited, in which case and then Needs_Finalization (T)
-- there is no Adjust procedure, and the object is built in and then not Aggr_In_Place
-- place. In Ada 95, the object can be limited but not and then not Is_Limited_View (T)
-- inherently limited if this allocator came from a return then
-- statement (we're allocating the result on the secondary -- An unchecked conversion is needed in the classwide case because
-- stack). In that case, the object will be moved, so we _do_ -- the designated type can be an ancestor of the subtype mark of
-- want to Adjust. -- the allocator.
if not Aggr_In_Place Insert_Action (N,
and then not Is_Limited_View (T) Make_Adjust_Call
then (Obj_Ref =>
Insert_Action (N, Unchecked_Convert_To (T,
Make_Explicit_Dereference (Loc,
Prefix => New_Occurrence_Of (Temp, Loc))),
Typ => T));
end if;
-- An unchecked conversion is needed in the classwide case -- Note: the accessibility check must be inserted after the call to
-- because the designated type can be an ancestor of the -- [Deep_]Adjust to ensure proper completion of the assignment.
-- subtype mark of the allocator.
Make_Adjust_Call Apply_Accessibility_Check (Temp);
(Obj_Ref =>
Unchecked_Convert_To (T,
Make_Explicit_Dereference (Loc,
Prefix => New_Occurrence_Of (Temp, Loc))),
Typ => T));
end if;
end if;
Rewrite (N, New_Occurrence_Of (Temp, Loc)); Rewrite (N, New_Occurrence_Of (Temp, Loc));
Analyze_And_Resolve (N, PtrT); Analyze_And_Resolve (N, PtrT);
......
...@@ -4640,19 +4640,20 @@ package body Exp_Ch7 is ...@@ -4640,19 +4640,20 @@ package body Exp_Ch7 is
function Is_Subprogram_Call (N : Node_Id) return Traverse_Result is function Is_Subprogram_Call (N : Node_Id) return Traverse_Result is
begin begin
-- Complex constructs are factored out by the expander and their -- A regular procedure or function call
-- occurrences are replaced with references to temporaries or
-- object renamings. Due to this expansion activity, inspect the if Nkind (N) in N_Subprogram_Call then
-- original tree to detect subprogram calls. Must_Hook := True;
return Abandon;
if Nkind_In (N, N_Identifier,
N_Object_Renaming_Declaration) -- Special cases
and then Original_Node (N) /= N
then
Detect_Subprogram_Call (Original_Node (N));
-- The original construct contains a subprogram call, there is -- Heavy expansion may relocate function calls outside the related
-- no point in continuing the tree traversal. -- node. Inspect the original node to detect the initial placement
-- of the call.
elsif Original_Node (N) /= N then
Detect_Subprogram_Call (Original_Node (N));
if Must_Hook then if Must_Hook then
return Abandon; return Abandon;
...@@ -4660,22 +4661,14 @@ package body Exp_Ch7 is ...@@ -4660,22 +4661,14 @@ package body Exp_Ch7 is
return OK; return OK;
end if; end if;
-- The original construct contains a subprogram call, there is no -- Generalized indexing always involves a function call
-- point in continuing the tree traversal.
elsif Nkind (N) = N_Object_Declaration elsif Nkind (N) = N_Indexed_Component
and then Present (Expression (N)) and then Present (Generalized_Indexing (N))
and then Nkind (Original_Node (Expression (N))) = N_Function_Call
then then
Must_Hook := True; Must_Hook := True;
return Abandon; return Abandon;
-- A regular procedure or function call
elsif Nkind (N) in N_Subprogram_Call then
Must_Hook := True;
return Abandon;
-- Keep searching -- Keep searching
else else
......
...@@ -862,16 +862,16 @@ package body Exp_Prag is ...@@ -862,16 +862,16 @@ package body Exp_Prag is
-- Generate a temporary to capture the value of the prefix: -- Generate a temporary to capture the value of the prefix:
-- Temp : <Pref type>; -- Temp : <Pref type>;
-- Place that temporary at the beginning of declarations, to
-- prevent anomalies in the GNATprove flow-analysis pass in
-- the precondition procedure that follows.
Decl := Decl :=
Make_Object_Declaration (Loc, Make_Object_Declaration (Loc,
Defining_Identifier => Temp, Defining_Identifier => Temp,
Object_Definition => Object_Definition =>
New_Occurrence_Of (Etype (Pref), Loc)); New_Occurrence_Of (Etype (Pref), Loc));
Set_No_Initialization (Decl);
-- Place that temporary at the beginning of declarations, to
-- prevent anomalies in the GNATprove flow-analysis pass in
-- the precondition procedure that follows.
Prepend_To (Decls, Decl); Prepend_To (Decls, Decl);
Analyze (Decl); Analyze (Decl);
......
...@@ -138,6 +138,36 @@ package body Exp_Unst is ...@@ -138,6 +138,36 @@ package body Exp_Unst is
Calls.Append (Call); Calls.Append (Call);
end Append_Unique_Call; end Append_Unique_Call;
---------------
-- Get_Level --
---------------
function Get_Level (Subp : Entity_Id; Sub : Entity_Id) return Nat is
Lev : Nat;
S : Entity_Id;
begin
Lev := 1;
S := Sub;
loop
if S = Subp then
return Lev;
else
S := Enclosing_Subprogram (S);
Lev := Lev + 1;
end if;
end loop;
end Get_Level;
----------------
-- Subp_Index --
----------------
function Subp_Index (Sub : Entity_Id) return SI_Type is
begin
pragma Assert (Is_Subprogram (Sub));
return SI_Type (UI_To_Int (Subps_Index (Sub)));
end Subp_Index;
----------------------- -----------------------
-- Unnest_Subprogram -- -- Unnest_Subprogram --
----------------------- -----------------------
...@@ -151,17 +181,9 @@ package body Exp_Unst is ...@@ -151,17 +181,9 @@ package body Exp_Unst is
-- This function returns the index of the enclosing subprogram which -- This function returns the index of the enclosing subprogram which
-- will have a Lev value one less than this. -- will have a Lev value one less than this.
function Get_Level (Sub : Entity_Id) return Nat;
-- Sub is either Subp itself, or a subprogram nested within Subp. This
-- function returns the level of nesting (Subp = 1, subprograms that
-- are immediately nested within Subp = 2, etc).
function Img_Pos (N : Pos) return String; function Img_Pos (N : Pos) return String;
-- Return image of N without leading blank -- Return image of N without leading blank
function Subp_Index (Sub : Entity_Id) return SI_Type;
-- Given the entity for a subprogram, return corresponding Subps index
function Upref_Name function Upref_Name
(Ent : Entity_Id; (Ent : Entity_Id;
Index : Pos; Index : Pos;
...@@ -196,26 +218,6 @@ package body Exp_Unst is ...@@ -196,26 +218,6 @@ package body Exp_Unst is
return Ret; return Ret;
end Enclosing_Subp; end Enclosing_Subp;
---------------
-- Get_Level --
---------------
function Get_Level (Sub : Entity_Id) return Nat is
Lev : Nat;
S : Entity_Id;
begin
Lev := 1;
S := Sub;
loop
if S = Subp then
return Lev;
else
S := Enclosing_Subprogram (S);
Lev := Lev + 1;
end if;
end loop;
end Get_Level;
------------- -------------
-- Img_Pos -- -- Img_Pos --
------------- -------------
...@@ -238,16 +240,6 @@ package body Exp_Unst is ...@@ -238,16 +240,6 @@ package body Exp_Unst is
end Img_Pos; end Img_Pos;
---------------- ----------------
-- Subp_Index --
----------------
function Subp_Index (Sub : Entity_Id) return SI_Type is
begin
pragma Assert (Is_Subprogram (Sub));
return SI_Type (UI_To_Int (Subps_Index (Sub)));
end Subp_Index;
----------------
-- Upref_Name -- -- Upref_Name --
---------------- ----------------
...@@ -561,7 +553,7 @@ package body Exp_Unst is ...@@ -561,7 +553,7 @@ package body Exp_Unst is
-- Make new entry in subprogram table if not already made -- Make new entry in subprogram table if not already made
declare declare
L : constant Nat := Get_Level (Ent); L : constant Nat := Get_Level (Subp, Ent);
begin begin
Subps.Append Subps.Append
((Ent => Ent, ((Ent => Ent,
......
...@@ -678,6 +678,14 @@ package Exp_Unst is ...@@ -678,6 +678,14 @@ package Exp_Unst is
-- Subprograms -- -- Subprograms --
----------------- -----------------
function Get_Level (Subp : Entity_Id; Sub : Entity_Id) return Nat;
-- Sub is either Subp itself, or a subprogram nested within Subp. This
-- function returns the level of nesting (Subp = 1, subprograms that
-- are immediately nested within Subp = 2, etc).
function Subp_Index (Sub : Entity_Id) return SI_Type;
-- Given the entity for a subprogram, return corresponding Subps index
procedure Unnest_Subprogram (Subp : Entity_Id; Subp_Body : Node_Id); procedure Unnest_Subprogram (Subp : Entity_Id; Subp_Body : Node_Id);
-- Subp is a library level subprogram which has nested subprograms, and -- Subp is a library level subprogram which has nested subprograms, and
-- Subp_Body is the corresponding N_Subprogram_Body node. This procedure -- Subp_Body is the corresponding N_Subprogram_Body node. This procedure
......
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