]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
exp_util.adb (Side_Effect_Free): Scalar if expressions can be SEF.
authorRobert Dewar <dewar@adacore.com>
Wed, 19 Feb 2014 11:07:31 +0000 (11:07 +0000)
committerArnaud Charlet <charlet@gcc.gnu.org>
Wed, 19 Feb 2014 11:07:31 +0000 (12:07 +0100)
2014-02-19  Robert Dewar  <dewar@adacore.com>

* exp_util.adb (Side_Effect_Free): Scalar if expressions can be SEF.

From-SVN: r207892

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

index dba833b5744de5b8a36c45a48063c9a305764883..64187583bd4d07b0878674052fd151cebf506536 100644 (file)
@@ -1,3 +1,7 @@
+2014-02-19  Robert Dewar  <dewar@adacore.com>
+
+       * exp_util.adb (Side_Effect_Free): Scalar if expressions can be SEF.
+
 2014-02-19  Robert Dewar  <dewar@adacore.com>
 
        * exp_util.adb: Update comments.
index ff18d08ef16c0edfc212d094532d4c5a2c9165a6..cab17742815ad60092a1b21d08348f183c8f2a04 100644 (file)
@@ -7675,6 +7675,9 @@ package body Exp_Util is
       Name_Req     : Boolean := False;
       Variable_Ref : Boolean := False) return Boolean
    is
+      Typ : constant Entity_Id := Etype (N);
+      --  Result type of the expression
+
       function Safe_Prefixed_Reference (N : Node_Id) return Boolean;
       --  The argument N is a construct where the Prefix is dereferenced if it
       --  is an access type and the result is a variable. The call returns True
@@ -7919,7 +7922,7 @@ package body Exp_Util is
       elsif VM_Target /= No_VM
          and then not Comes_From_Source (N)
          and then Nkind (Parent (N)) = N_Object_Renaming_Declaration
-         and then Is_Class_Wide_Type (Etype (N))
+         and then Is_Class_Wide_Type (Typ)
       then
          return True;
       end if;
@@ -7981,12 +7984,16 @@ package body Exp_Util is
                 Side_Effect_Free
                   (First (Parameter_Associations (N)), Name_Req, Variable_Ref);
 
-         --  An IF expression is side effect free if its components are all
-         --  side effect free (conditions and then actions and else actions).
+         --  An IF expression is side effect free if it's of a scalar type, and
+         --  all its components are all side effect free (conditions and then
+         --  actions and else actions). We restrict to scalar types, since it
+         --  is annoying to deal with things like (if A then B else C)'First
+         --  where the type involved is a string type.
 
-         --  when N_If_Expression =>
-         --  return Side_Effect_Free (Expressions (N), Name_Req, Variable_Ref);
-         --  commented out for now, caused some crashes ???
+         when N_If_Expression =>
+            return Is_Scalar_Type (Typ)
+              and then
+                Side_Effect_Free (Expressions (N), Name_Req, Variable_Ref);
 
          --  An indexed component is side effect free if it is a side
          --  effect free prefixed reference and all the indexing
@@ -8014,7 +8021,7 @@ package body Exp_Util is
 
          when N_Selected_Component =>
             if Nkind (Parent (N)) = N_Explicit_Dereference
-              and then Has_Non_Standard_Rep (Designated_Type (Etype (N)))
+              and then Has_Non_Standard_Rep (Designated_Type (Typ))
             then
                return False;
             else