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] Fix even the second testcase from PR middle-end/38343


Hi!

I haven't noticed there is a second testcase in the PR, which is failing for
a different reason.  The following patch fixes it.  len passed to
fold_builtin_memory_op is size_type_node (for mempcpy) and ssizetype (for
stpcpy), so needs to be converted to sizetype to pass build2
(POINTER_PLUS_EXPR, ...) checking.

Bootstrapped/regtested on x86_64-linux, ok for trunk?

2008-12-02  Jakub Jelinek  <jakub@redhat.com>

	PR middle-end/38343
	* builtins.c (fold_builtin_memory_op): Convert len to sizetype
	before using it in POINTER_PLUS_EXPR.

	* gcc.c-torture/compile/pr38343-2.c: New test.

--- gcc/builtins.c.jj	2008-12-01 18:52:04.000000000 +0100
+++ gcc/builtins.c	2008-12-02 13:41:00.000000000 +0100
@@ -8991,6 +8991,7 @@ fold_builtin_memory_op (tree dest, tree 
     len = fold_build2 (MINUS_EXPR, TREE_TYPE (len), len,
 		       ssize_int (1));
 
+  len = fold_convert (sizetype, len);
   dest = fold_build2 (POINTER_PLUS_EXPR, TREE_TYPE (dest), dest, len);
   dest = fold_convert (type, dest);
   if (expr)
--- gcc/testsuite/gcc.c-torture/compile/pr38343-2.c.jj	2008-12-02 14:16:38.000000000 +0100
+++ gcc/testsuite/gcc.c-torture/compile/pr38343-2.c	2008-12-02 14:13:49.000000000 +0100
@@ -0,0 +1,12 @@
+/* PR middle-end/38343 */
+
+static struct S
+{
+  char f[6];
+} s[] = { {"01000"} };
+
+char *
+foo (void)
+{
+  return __builtin_stpcpy (s[0].f, "S0022");
+}

	Jakub


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