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]

Re: [PATCH][4.1/4.2] Fix PR27260, fallout of fix for PR27095


On Thu, Apr 27, 2006 at 06:43:33AM -0600, Roger Sayle wrote:
> On Thu, 27 Apr 2006, Alan Modra wrote:
> >
> > 	PR middle-end/27260
> > 	* builtins.c (expand_builtin_memset): Expand val in original mode.
> >
> > OK to apply?
> 
> This is OK for mainline (and 4.1 after a week) provided that you add
> suitable test cases as requested by Richard G.  Thanks.

The testcase for pr27095 proved a little tricky.  The one Richard
Guenther posted didn't fail on an unpatched compiler.  Apparently we
need a builtin strlen in the memset arg;  my_strlen doesn't trigger the
bug.  Of course using strlen in the test runs the risk that it might be
optimized away, if not now then with some future version of gcc.  So
scanning for exactly one "strlen" in the assembly might fail.  Here's
what I'll commit.

2006-04-28  Alan Modra  <amodra@bigpond.net.au>

	PR middle-end/27095
	* gcc.dg/pr27095.c: New.

2006-04-28  Jakub Jelinek  <jakub@redhat.com>

	PR middle-end/27260
	* gcc.c-torture/execute/pr27260.c: New.

Index: gcc/testsuite/gcc.dg/pr27095.c
===================================================================
--- gcc/testsuite/gcc.dg/pr27095.c	(revision 0)
+++ gcc/testsuite/gcc.dg/pr27095.c	(revision 0)
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+extern void *memset (void *, int, __SIZE_TYPE__);
+extern __SIZE_TYPE__ strlen (const char *);
+
+int
+main (int argc, char **argv)
+{
+  char x[8] = "abc";
+  memset (x, argc, strlen (x));
+  return 0;
+}
+/* { dg-final { scan-assembler-not "(?n)strlen\(.*\n\)+.*strlen" } } */
Index: gcc/testsuite/gcc.c-torture/execute/pr27260.c
===================================================================
--- gcc/testsuite/gcc.c-torture/execute/pr27260.c	(revision 0)
+++ gcc/testsuite/gcc.c-torture/execute/pr27260.c	(revision 0)
@@ -0,0 +1,33 @@
+/* PR middle-end/27260 */
+
+extern void abort (void);
+extern void *memset (void *, int, __SIZE_TYPE__);
+
+char buf[65];
+
+void
+foo (int x)
+{
+  memset (buf, x != 2 ? 1 : 0, 64);
+}
+
+int
+main (void)
+{
+  int i;
+  buf[64] = 2;
+  for (i = 0; i < 64; i++)
+    if (buf[i] != 0)
+      abort ();
+  foo (0);
+  for (i = 0; i < 64; i++)
+    if (buf[i] != 1)
+      abort ();
+  foo (2);
+  for (i = 0; i < 64; i++)
+    if (buf[i] != 0)
+      abort ();
+  if (buf[64] != 2)
+    abort ();
+  return 0;
+}

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre


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