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 to fix string-opt-9.c "regression" with builtin strcat


After I installed my recent builtin strcat change, I got a spank from
the regressions tester.  There was never any code-gen problem, it was
a mistake in the testcase.  Essentially the assumption I made about
"store by pieces" always succeeding even for very small strings was
incorrect.

Looking in another test, execute/builtins/string-4.c, it appears that
x86 and x86_64 are the only platforms where we can reliably count on
"store by pieces" always working.  So I moved string-opt-9.c to the
execute/builtins/ framework and modified it accordingly.

I don't have access to a darwin box to see if it'll fix the regression
checker's complaint and it's an execute failure so a cross compiler
won't help.  But I did get a similar failure on irix6.5 and this patch
makes it go away so I suspect it'll fix everyone's problems.

Tested with "make check" on mips-sgi-irix6.5 and sparc-sun-solaris2.7.
Ok for mainline?

		Thanks,
		--Kaveh


2003-08-13  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>

	* gcc.c-torture/execute/builtins/lib/strcat.c: New.
	* gcc.c-torture/execute/builtins/string-9-lib.c: New.
	* gcc.c-torture/execute/builtins/string-9.c: New, from
	string-opt-9.c.  Adjust for execute/builtins framework.
	* gcc.c-torture/execute/string-opt-9.c: Delete.

diff -rupN orig/egcc-CVS20030812/gcc/testsuite/gcc.c-torture/execute/builtins/lib/strcat.c egcc-CVS20030812/gcc/testsuite/gcc.c-torture/execute/builtins/lib/strcat.c
--- orig/egcc-CVS20030812/gcc/testsuite/gcc.c-torture/execute/builtins/lib/strcat.c	1969-12-31 19:00:00.000000000 -0500
+++ egcc-CVS20030812/gcc/testsuite/gcc.c-torture/execute/builtins/lib/strcat.c	2003-08-13 10:33:56.068857906 -0400
@@ -0,0 +1,19 @@
+extern int inside_main;
+extern void abort(void);
+
+char *
+strcat (char *dst, const char *src)
+{
+  char *p = dst;
+  
+#ifdef __OPTIMIZE__
+  if (inside_main)
+    abort ();
+#endif
+
+  while (*p)
+    p++;
+  while ((*p++ = *src++))
+    ;
+  return dst;
+}
diff -rupN orig/egcc-CVS20030812/gcc/testsuite/gcc.c-torture/execute/builtins/string-9-lib.c egcc-CVS20030812/gcc/testsuite/gcc.c-torture/execute/builtins/string-9-lib.c
--- orig/egcc-CVS20030812/gcc/testsuite/gcc.c-torture/execute/builtins/string-9-lib.c	1969-12-31 19:00:00.000000000 -0500
+++ egcc-CVS20030812/gcc/testsuite/gcc.c-torture/execute/builtins/string-9-lib.c	2003-08-13 10:33:45.639309482 -0400
@@ -0,0 +1 @@
+#include "lib/strcat.c"
diff -rupN orig/egcc-CVS20030812/gcc/testsuite/gcc.c-torture/execute/builtins/string-9.c egcc-CVS20030812/gcc/testsuite/gcc.c-torture/execute/builtins/string-9.c
--- orig/egcc-CVS20030812/gcc/testsuite/gcc.c-torture/execute/builtins/string-9.c	1969-12-31 19:00:00.000000000 -0500
+++ egcc-CVS20030812/gcc/testsuite/gcc.c-torture/execute/builtins/string-9.c	2003-08-13 10:33:46.319249465 -0400
@@ -0,0 +1,79 @@
+/* Copyright (C) 2000, 2003  Free Software Foundation.
+
+   Ensure all expected transformations of builtin strcat occur and
+   perform correctly.
+
+   Written by Kaveh R. Ghazi, 11/27/2000.  */
+
+extern int inside_main;
+extern void abort (void);
+typedef __SIZE_TYPE__ size_t;
+extern char *strcat (char *, const char *);
+extern char *strcpy (char *, const char *);
+extern int strcmp (const char *, const char *);
+extern void *memset (void *, int, size_t);
+extern int memcmp (const void *, const void *, size_t);
+#define RESET_DST_WITH(FILLER) \
+  do { memset (dst, 'X', sizeof (dst)); strcpy (dst, (FILLER)); } while (0)
+
+void main_test (void)
+{
+  const char *const s1 = "hello world";
+  const char *const s2 = "";
+  char dst[64], *d2;
+  
+  RESET_DST_WITH (s1);
+  if (strcat (dst, "") != dst || strcmp (dst, s1))
+    abort();
+  RESET_DST_WITH (s1);
+  if (strcat (dst, s2) != dst || strcmp (dst, s1))
+    abort();
+  RESET_DST_WITH (s1); d2 = dst;
+  if (strcat (++d2, s2) != dst+1 || d2 != dst+1 || strcmp (dst, s1))
+    abort();
+  RESET_DST_WITH (s1); d2 = dst;
+  if (strcat (++d2+5, s2) != dst+6 || d2 != dst+1 || strcmp (dst, s1))
+    abort();
+  RESET_DST_WITH (s1); d2 = dst;
+  if (strcat (++d2+5, s1+11) != dst+6 || d2 != dst+1 || strcmp (dst, s1))
+    abort();
+
+#ifndef __OPTIMIZE_SIZE__
+# if !defined __i386__ && !defined __x86_64__
+  /* The functions below might not be optimized into direct stores on all
+     arches.  It depends on how many instructions would be generated and
+     what limits the architecture chooses in STORE_BY_PIECES_P.  */
+  inside_main = 0;
+# endif
+
+  RESET_DST_WITH (s1);
+  if (strcat (dst, " 1111") != dst
+      || memcmp (dst, "hello world 1111\0XXX", 20))
+    abort();
+  
+  RESET_DST_WITH (s1);
+  if (strcat (dst+5, " 2222") != dst+5
+      || memcmp (dst, "hello world 2222\0XXX", 20))
+    abort();
+  
+  RESET_DST_WITH (s1); d2 = dst;
+  if (strcat (++d2+5, " 3333") != dst+6 || d2 != dst+1
+      || memcmp (dst, "hello world 3333\0XXX", 20))
+    abort();
+  
+  RESET_DST_WITH (s1);
+  strcat (strcat (strcat (strcat (strcat (strcat (dst, ": this "), ""),
+				  "is "), "a "), "test"), ".");
+  if (memcmp (dst, "hello world: this is a test.\0X", 30))
+    abort();
+
+  /* Set inside_main again.  */
+  inside_main = 1;
+#endif
+
+  /* Test at least one instance of the __builtin_ style.  We do this
+     to ensure that it works and that the prototype is correct.  */
+  RESET_DST_WITH (s1);
+  if (__builtin_strcat (dst, "") != dst || strcmp (dst, s1))
+    abort();
+}


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