[testsuite] Yet another loop failure

Jakub Jelinek jakub@redhat.com
Tue Aug 1 03:49:00 GMT 2000


Hi!

This is miscompiled with -O2 on at least i386 and sparc.
The first part (ie. biv[0] <-> biv[3] is done correctly, but then
loop forgots bp and sp have been changed and biv[1] <-> biv[2] exchange
is done as biv[0] <-> biv[1]. Last biv is correctly incremented by 4.

2000-08-01  Jakub Jelinek  <jakub@redhat.com>

	* gcc.c-torture/execute/20000801-1.c: New test.

--- gcc/testsuite/gcc.c-torture/execute/20000801-1.c.jj	Tue Aug  1 12:44:09 2000
+++ gcc/testsuite/gcc.c-torture/execute/20000801-1.c	Tue Aug  1 12:16:04 2000
@@ -0,0 +1,39 @@
+extern void abort(void);
+extern void exit(int);
+
+void
+foo (char *bp, unsigned n)
+{
+  register char c;
+  register char *ep = bp + n;
+  register char *sp;
+
+  while (bp < ep)
+    {
+      sp = bp + 3;
+      c = *sp;
+      *sp = *bp;
+      *bp++ = c;
+      sp = bp + 1;
+      c = *sp;
+      *sp = *bp;
+      *bp++ = c;
+      bp += 2;
+    }
+}
+
+int main(void)
+{
+  int one = 1;
+
+  if (sizeof(int) != 4 * sizeof(char))
+    exit(0);
+
+  foo((char *)&one, sizeof(one));
+  foo((char *)&one, sizeof(one));
+
+  if (one != 1)
+    abort();
+
+  exit(0);
+}
	Jakub


More information about the Gcc-patches mailing list