This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix ICE on strcpy expansion in 4.4 (PR middle-end/42049)
- From: Jakub Jelinek <jakub at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Thu, 3 Dec 2009 08:07:51 -0500
- Subject: [PATCH] Fix ICE on strcpy expansion in 4.4 (PR middle-end/42049)
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
Hi!
As has been noted several times already, expand_expr after move to SSA
doesn't expect COMPOUND_EXPR to be seen, but various fold_builtin_* calls in
expand_builtin_* can create it. This is how this has been fixed in other
cases. In 4.5, Michael removed the fold_* calls from the expanders after
scheduling a fab pass near end of the tree passes.
Ok for 4.4 and the testcase also for trunk?
2009-12-03 Jakub Jelinek <jakub@redhat.com>
PR middle-end/42049
* builtins.c (expand_builtin_strcpy_args): Handle COMPOUND_EXPRs
potentially returned from folding strcpy.
* gcc.c-torture/compile/pr42049.c: New test.
--- gcc/builtins.c.jj 2009-08-31 15:19:57.000000000 +0200
+++ gcc/builtins.c 2009-12-03 11:13:34.000000000 +0100
@@ -3712,7 +3712,15 @@ expand_builtin_strcpy_args (tree fndecl,
{
tree result = fold_builtin_strcpy (fndecl, dest, src, 0);
if (result)
- return expand_expr (result, target, mode, EXPAND_NORMAL);
+ {
+ while (TREE_CODE (result) == COMPOUND_EXPR)
+ {
+ expand_expr (TREE_OPERAND (result, 0), const0_rtx, VOIDmode,
+ EXPAND_NORMAL);
+ result = TREE_OPERAND (result, 1);
+ }
+ return expand_expr (result, target, mode, EXPAND_NORMAL);
+ }
return expand_movstr (dest, src, target, /*endp=*/0);
}
--- gcc/testsuite/gcc.c-torture/compile/pr42049.c.jj 2009-12-03 11:14:40.000000000 +0100
+++ gcc/testsuite/gcc.c-torture/compile/pr42049.c 2009-12-03 11:14:16.000000000 +0100
@@ -0,0 +1,27 @@
+/* PR middle-end/42049 */
+
+extern char *strcpy (char *s1, const char *s2);
+struct S { char s[4]; };
+
+int
+foo (int x, char **y)
+{
+ char const *a;
+ char const *b;
+ struct S s[9];
+ long i;
+ if (x > 1)
+ a = y[1];
+ else
+ a = "abc";
+ if (x > 2)
+ b = y[2];
+ else
+ b = "def";
+ strcpy (s[0].s, a);
+ strcpy (s[1].s, b);
+ for (i = 2; i < x - 2 && i < 8; i++)
+ strcpy (s[i].s, y[i + 1]);
+ s[i].s[0] = '\0';
+ return 0;
+}
Jakub