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]

Patch expand_builtin_stpcpy to only expand for string constants


As mentioned by Jakub here:
http://gcc.gnu.org/ml/gcc-patches/2003-04/msg02122.html

expanding stpcpy can pessimize code when calculating the return value  if the src string is a runtime
expression.  This patch limits the expansion

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-CVS20030504/gcc/builtins.c egcc-CVS20030504/gcc/builtins.c
--- orig/egcc-CVS20030504/gcc/builtins.c	2003-05-04 01:32:45.000000000 -0400
+++ egcc-CVS20030504/gcc/builtins.c	2003-05-04 13:57:06.965181974 -0400
@@ -2469,8 +2469,14 @@ expand_builtin_stpcpy (arglist, target, 
   else
     {
       tree newarglist;
-      tree len = c_strlen (TREE_VALUE (TREE_CHAIN (arglist)));
-      if (len == 0)
+      tree src = TREE_VALUE (TREE_CHAIN (arglist));
+      tree len = c_strlen (src);
+
+      /* 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.  */
+      if (!len || !c_getstr(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]