From: ghazi Date: Mon, 5 May 2003 21:14:46 +0000 (+0000) Subject: * builtins.c (expand_builtin_stpcpy): Only expand when the length X-Git-Url: http://git.sourceforge.jp/view?a=commitdiff_plain;h=c04062e9f5efb65a46396ad738d4387de7d3ca82;p=pf3gnuchains%2Fgcc-fork.git * builtins.c (expand_builtin_stpcpy): Only expand when the length of the source string can be evaluated at compile-time. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@66503 138bc75d-0d04-0410-961f-82ee72b054a4 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 3cf8d08105c..ed14f650c0d 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2003-05-05 Kaveh R. Ghazi + + * 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 * testsuite/gcc.c-torture/compile/simd-6.c: New. diff --git a/gcc/builtins.c b/gcc/builtins.c index dfc17e569fd..feee5312a6c 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -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)));