summaryrefslogtreecommitdiff
path: root/support/regression/tests/gcc-torture-execute-20030717-1.c
blob: af316a1c5e22fa236db7423ca29a6ab24393b5f2 (plain) (blame)
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
   20030717-1.c from the execute part of the gcc torture tests.
 */

#include <testfwk.h>

#ifdef __SDCC
#pragma std_c99
#endif

#include <string.h>

/* PR target/11087
   This testcase was miscompiled on ppc64, because basic_induction_var called
   convert_modes, yet did not expect it to emit any new instructions.
   Those were emitted at the end of the function and destroyed during life
   analysis, while the program used uninitialized pseudos created by
   convert_modes.  */

#ifndef __SDCC_pdk14 // lack of memory
struct A
{
  unsigned short a1;
  unsigned long a2;
};

struct B
{
  int b1, b2, b3, b4, b5;
};

struct C
{
  struct B c1[1];
  int c2, c3;
};

static
int foo (int x)
{
  return  x < 0 ? -x : x;
}

int bar (struct C *x, struct A *y)
{
  int a = x->c3;
  const int b = y->a1 >> 9;
  const unsigned long c = y->a2;
  int d = a;
  unsigned long e, f;

  f = foo (c - x->c1[d].b4);
  do
    {
      if (d <= 0)
	d = x->c2;
      d--;

      e = foo (c-x->c1[d].b4);
      if (e < f)
	a = d;
    }
  while (d != x->c3);
  x->c1[a].b4 = c + b;
  return a;
}
#endif

void
testTortureExecute (void)
{
#ifndef __SDCC_pdk14 // lack of memory
  struct A a;
  struct C b;
  int c;

  a.a1 = 512;
  a.a2 = 4242;
  memset (&b, 0, sizeof (b));
  b.c1[0].b3 = 424242;
  b.c2 = 1;
  c = bar (&b, &a);
  return;
#endif
}