summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.c-torture/execute/loop-15.c
blob: 8cb5125a29ea691731155d245c819a0fcf8a2822 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/* Bombed with a segfault on powerpc-linux.  doloop.c generated wrong
   loop count.  */
void
foo (unsigned long *start, unsigned long *end)
{
  unsigned long *temp = end - 1;

  while (end > start)
    *end-- = *temp--;
}

int
main (void)
{
  unsigned long a[5];
  int start, end, k;

  for (start = 0; start < 5; start++)
    for (end = 0; end < 5; end++)
      {
	for (k = 0; k < 5; k++)
	  a[k] = k;

	foo (a + start, a + end);

	for (k = 0; k <= start; k++)
	  if (a[k] != k)
	    abort ();

	for (k = start + 1; k <= end; k++)
	  if (a[k] != k - 1)
	    abort ();

	for (k = end + 1; k < 5; k++)
	  if (a[k] != k)
	    abort ();
      }

  return 0;
}