OSDN Git Service

2011-08-02 Javier Miranda <miranda@adacore.com>
authorcharlet <charlet@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 2 Aug 2011 10:02:23 +0000 (10:02 +0000)
committercharlet <charlet@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 2 Aug 2011 10:02:23 +0000 (10:02 +0000)
* 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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@177120 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ada/ChangeLog
gcc/ada/exp_util.adb
gcc/ada/sem_res.adb

index e7e1283..2ade68e 100644 (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.
index 03e41c9..8923702 100644 (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 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
 
-      if Side_Effect_Free (Exp) or else not Expander_Active then
+      elsif Side_Effect_Free (Exp) then
          return;
       end if;
 
index d6a1ccf..a94ecc2 100644 (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