]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
builtins.c (expand_builtin_stpcpy): Only expand when the length of the source string...
authorKaveh R. Ghazi <ghazi@caip.rutgers.edu>
Mon, 5 May 2003 21:14:46 +0000 (21:14 +0000)
committerKaveh Ghazi <ghazi@gcc.gnu.org>
Mon, 5 May 2003 21:14:46 +0000 (21:14 +0000)
* builtins.c (expand_builtin_stpcpy): Only expand when the length
of the source string can be evaluated at compile-time.

From-SVN: r66503

gcc/ChangeLog
gcc/builtins.c

index 3cf8d08105c8972620d7415935c2210f0d52e9af..ed14f650c0df9708e864c6bde6b8023c0be6caf6 100644 (file)
@@ -1,3 +1,8 @@
+2003-05-05  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>
+
+       * builtins.c (expand_builtin_stpcpy): Only expand when the length
+       of the source string can be evaluated at compile-time.
+
 2003-05-05  Aldy Hernandez  <aldyh@redhat.com>
 
         * testsuite/gcc.c-torture/compile/simd-6.c: New.
index dfc17e569fdad06886b6589e3f05f790516d3c8c..feee5312a6c30f020f5342dfb3deaaa47c54e4df 100644 (file)
@@ -2508,7 +2508,7 @@ expand_builtin_stpcpy (arglist, target, mode)
   else
     {
       tree newarglist;
-      tree len;
+      tree src, len;
 
       /* If return value is ignored, transform stpcpy into strcpy.  */
       if (target == const0_rtx)
@@ -2527,8 +2527,12 @@ expand_builtin_stpcpy (arglist, target, mode)
                              target, mode, EXPAND_NORMAL);
        }
 
-      len = c_strlen (TREE_VALUE (TREE_CHAIN (arglist)));
-      if (len == 0)
+      /* Ensure we get an actual string who length can be evaluated at
+         compile-time, not an expression containing a string.  This is
+         because the latter will potentially produce pessimized code
+         when used to produce the return value.  */
+      src = TREE_VALUE (TREE_CHAIN (arglist));
+      if (! c_getstr (src) || ! (len = c_strlen (src)))
        return 0;
 
       len = fold (size_binop (PLUS_EXPR, len, ssize_int (1)));