This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
PATCH: fix gcc.c-torture/execute/builtins/strlen.c
- From: Ben Elliston <bje at au1 dot ibm dot com>
- To: gcc-patches at gcc dot gnu dot org
- Cc: janis187 at us dot ibm dot com
- Date: Wed, 25 Oct 2006 11:42:33 +1000
- Subject: PATCH: fix gcc.c-torture/execute/builtins/strlen.c
This test uses strcpy for its own devices. On some systems I've
encountered, strcpy may use strlen, which this test overrides to call
abort(). This patch works around that.
Okay for mainline?
Ben
2006-10-25 Ben Elliston <bje@au.ibm.com>
* gcc.c-torture/execute/builtins/strlen.c: Do not use strcpy.
Copy the strings manually, as strcpy may call strlen.
Index: gcc.c-torture/execute/builtins/strlen.c
===================================================================
--- gcc.c-torture/execute/builtins/strlen.c (revision 118014)
+++ gcc.c-torture/execute/builtins/strlen.c (working copy)
@@ -8,7 +8,14 @@
Additional tests written by Roger Sayle, 11/02/2001:
Ensure all builtin strlen comparisons against zero are optimized
and perform correctly. The multiple calls to strcpy are to prevent
- the potentially "pure" strlen calls from being removed by CSE. */
+ the potentially "pure" strlen calls from being removed by CSE.
+
+ Modifed by Ben Elliston, 2006-10-25:
+ The multiple calls to strcpy that Roger mentions above are
+ problematic on systems where strcpy is implemented using strlen
+ (which this test overrides to call abort). So, rather than use
+ strcpy, we perform the identical operations using array indexing
+ and char assignments. */
extern void abort (void);
extern __SIZE_TYPE__ strlen (const char *);
@@ -33,27 +40,27 @@ main_test(void)
abort ();
ptr = str;
- strcpy (ptr, "nts");
+ ptr[0] = 'n'; ptr[1] = 't'; ptr[2] = 's'; ptr[3] = '\0';
if (strlen (ptr) == 0)
abort ();
- strcpy (ptr, "nts");
+ ptr[0] = 'n'; ptr[1] = 't'; ptr[2] = 's'; ptr[3] = '\0';
if (strlen (ptr) < 1)
abort ();
- strcpy (ptr, "nts");
+ ptr[0] = 'n'; ptr[1] = 't'; ptr[2] = 's'; ptr[3] = '\0';
if (strlen (ptr) <= 0)
abort ();
- strcpy (ptr, "nts");
+ ptr[0] = 'n'; ptr[1] = 't'; ptr[2] = 's'; ptr[3] = '\0';
if (strlen (ptr+3) != 0)
abort ();
- strcpy (ptr, "nts");
+ ptr[0] = 'n'; ptr[1] = 't'; ptr[2] = 's'; ptr[3] = '\0';
if (strlen (ptr+3) > 0)
abort ();
- strcpy (ptr, "nts");
+ ptr[0] = 'n'; ptr[1] = 't'; ptr[2] = 's'; ptr[3] = '\0';
if (strlen (str+3) >= 1)
abort ();