This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Patch expand_builtin_stpcpy to only expand for string constants


 > From: Richard Henderson <rth@redhat.com>
 > 
 > On Sun, May 04, 2003 at 02:22:38PM -0400, Kaveh R. Ghazi wrote:
 > > 	* builtins.c (expand_builtin_stpcpy): Only expand when the length
 > > 	of the source string can be evaluated at compile-time.
 > 
 > Ok.
 > r~

It didn't apply cleanly after Jakub's most recent patch.  So since I
had to muck with it anyway, I also took the opportunity to swap the
order in the `if' stmt so that it short-circuits better.

Here's what I installed.

2003-05-04  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.

diff -rup orig/egcc-CVS20030505/gcc/builtins.c egcc-CVS20030505/gcc/builtins.c
--- orig/egcc-CVS20030505/gcc/builtins.c	2003-05-05 16:36:56.000000000 -0400
+++ egcc-CVS20030505/gcc/builtins.c	2003-05-05 16:45:03.436401414 -0400
@@ -2508,7 +2508,7 @@ expand_builtin_stpcpy (arglist, target, 
   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, 
 			      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)));


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]