builtins.c (expand_builtin_mathfn): Make sure not to expand the argument more than...
authorMark Mitchell <mark@codesourcery.com>
Wed, 15 Dec 1999 20:56:58 +0000 (20:56 +0000)
committerMark Mitchell <mmitchel@gcc.gnu.org>
Wed, 15 Dec 1999 20:56:58 +0000 (20:56 +0000)
* builtins.c (expand_builtin_mathfn): Make sure not to expand the
argument more than once.

From-SVN: r30963

gcc/ChangeLog
gcc/builtins.c

index 5e8cfedadd0eec76eb21b9bd1d5650912d9f631c..0462e45f374d95744d4ec694d0971fb605b6a0fc 100644 (file)
@@ -1,3 +1,8 @@
+1999-12-15  Mark Mitchell  <mark@codesourcery.com>
+
+       * builtins.c (expand_builtin_mathfn): Make sure not to expand the
+       argument more than once.
+
 1999-12-15  Jason Merrill  <jason@casey.cygnus.com>
 
        * stmt.c (expand_decl): Expand upper bound of a dynamic array.
index ffc84fd9ccd120c17511bbd520e634ce538ed99f..f03a53f864ce19ae8ca817f93aaee2682b6e0321 100644 (file)
@@ -1182,9 +1182,16 @@ expand_builtin_mathfn (exp, target, subtarget)
       && TREE_CODE (TREE_VALUE (arglist)) != PARM_DECL)
     {
       exp = copy_node (exp);
-      arglist = copy_node (arglist);
       TREE_OPERAND (exp, 1) = arglist;
+      /* Wrap the computation of the argument in a SAVE_EXPR.  That
+        way, if we need to expand the argument again (as in the
+        flag_errno_math case below where we cannot directly set
+        errno), we will not perform side-effects more than once.
+        Note that here we're mutating the original EXP as well as the
+        copy; that's the right thing to do in case the original EXP
+        is expanded later.  */
       TREE_VALUE (arglist) = save_expr (TREE_VALUE (arglist));
+      arglist = copy_node (arglist);
     }
   op0 = expand_expr (TREE_VALUE (arglist), subtarget, VOIDmode, 0);