Patch expand_builtin_stpcpy to only expand for string constants
Kaveh R. Ghazi
ghazi@caip.rutgers.edu
Sun May 4 18:22:00 GMT 2003
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)));
More information about the Gcc-patches
mailing list