exp_util.adb (Safe_Prefixed_Reference): Do not consider safe an in-mode parameter whose type is an access type since it...

2011-08-02  Javier Miranda  <miranda@adacore.com>

	* exp_util.adb (Safe_Prefixed_Reference): Do not consider safe an
	in-mode parameter whose type is an access type since it can be used to
	modify its designated object. Enforce code that handles as safe an
	access type that is not access-to-constant but it is the result of a
	previous removal of side-effects.
	(Remove_Side_Effects): Minor code reorganization of cases which require
	no action. Done to incorporate documentation on new cases uncovered
	working in this ticket: no action needed if this routine was invoked
	too early and the nodes are not yet decorated.
	* sem_res.adb (Resolve_Slice): Minor code cleanup replacling two calls
	to routine Remove_Side_Effects by calls to Force_Evaluation since they
	were issued with actuals that are implicitly provided by
	Force_Evaluation.

From-SVN: r177120
This commit is contained in:
Javier Miranda 2011-08-02 10:02:23 +00:00 committed by Arnaud Charlet
parent 218e6deed7
commit cae81f177d
3 changed files with 43 additions and 15 deletions

View File

@ -1,3 +1,19 @@
2011-08-02 Javier Miranda <miranda@adacore.com>
* exp_util.adb (Safe_Prefixed_Reference): Do not consider safe an
in-mode parameter whose type is an access type since it can be used to
modify its designated object. Enforce code that handles as safe an
access type that is not access-to-constant but it is the result of a
previous removal of side-effects.
(Remove_Side_Effects): Minor code reorganization of cases which require
no action. Done to incorporate documentation on new cases uncovered
working in this ticket: no action needed if this routine was invoked
too early and the nodes are not yet decorated.
* sem_res.adb (Resolve_Slice): Minor code cleanup replacling two calls
to routine Remove_Side_Effects by calls to Force_Evaluation since they
were issued with actuals that are implicitly provided by
Force_Evaluation.
2011-08-02 Robert Dewar <dewar@adacore.com>
* sem_ch3.adb, sem_res.adb: Minor reformatting.

View File

@ -4616,21 +4616,19 @@ package body Exp_Util is
-- If the prefix is of an access type that is not access-to-constant,
-- then this construct is a variable reference, which means it is to
-- be considered to have side effects if Variable_Ref is set True
-- Exception is an access to an entity that is a constant or an
-- in-parameter which does not come from source, and is the result
-- of a previous removal of side-effects.
-- be considered to have side effects if Variable_Ref is set True.
elsif Is_Access_Type (Etype (Prefix (N)))
and then not Is_Access_Constant (Etype (Prefix (N)))
and then Variable_Ref
then
if not Is_Entity_Name (Prefix (N)) then
return False;
else
return Ekind (Entity (Prefix (N))) = E_Constant
or else Ekind (Entity (Prefix (N))) = E_In_Parameter;
end if;
-- Exception is a prefix that is the result of a previous removal
-- of side-effects.
return Is_Entity_Name (Prefix (N))
and then not Comes_From_Source (Prefix (N))
and then Ekind (Entity (Prefix (N))) = E_Constant
and then Is_Internal_Name (Chars (Entity (Prefix (N))));
-- If the prefix is an explicit dereference then this construct is a
-- variable reference, which means it is to be considered to have
@ -4945,10 +4943,24 @@ package body Exp_Util is
-- Start of processing for Remove_Side_Effects
begin
-- If we are side effect free already or expansion is disabled,
-- there is nothing to do.
-- Handle cases in which there is nothing to do
if Side_Effect_Free (Exp) or else not Expander_Active then
if not Expander_Active then
return;
-- Cannot generate temporaries if the invocation to remove side effects
-- was issued too early and the type of the expression is not resolved
-- (this happens because routines Duplicate_Subexpr_XX implicitly invoke
-- Remove_Side_Effects).
elsif No (Exp_Type)
or else Ekind (Exp_Type) = E_Access_Attribute_Type
then
return;
-- No action needed for side-effect free expressions
elsif Side_Effect_Free (Exp) then
return;
end if;

View File

@ -8631,8 +8631,8 @@ package body Sem_Res is
-- Ensure that side effects in the bounds are properly handled
Remove_Side_Effects (Low_Bound (Drange), Variable_Ref => True);
Remove_Side_Effects (High_Bound (Drange), Variable_Ref => True);
Force_Evaluation (Low_Bound (Drange));
Force_Evaluation (High_Bound (Drange));
-- Do not apply the range check to nodes associated with the
-- frontend expansion of the dispatch table. We first check