summaryrefslogtreecommitdiff
path: root/support/regression/tests/gcc-torture-execute-pr39100.c
blob: 8487f024279273be7196414594d1fe6e78d106ac (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
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
/*
   pr39100.c from the execute part of the gcc torture tests.
 */

#include <testfwk.h>

#ifdef __SDCC
#pragma std_c99
#pragma disable_warning 85
#endif

/* Bad PTA results (incorrect store handling) was causing us to delete
   *na = 0 store.  */

typedef struct E
{
  int p;
  struct E *n;
} *EP;   

typedef struct C
{
  EP x;
  short cn, cp; 
} *CP;

#ifndef __SDCC_pdk14 // Lack of memory
CP
foo (CP h, EP x)
{
  EP pl = 0, *pa = &pl;
  EP nl = 0, *na = &nl;
  EP n;

  while (x)
    {
      n = x->n;   
      if ((x->p & 1) == 1) 
        {
          h->cp++;
          *pa = x;
          pa = &((*pa)->n);
        }
      else
        {
          h->cn++;
          *na = x;
          na = &((*na)->n);
        }    
      x = n;
    }
  *pa = nl;
  *na = 0;
  h->x = pl;
  return h;
}
#endif

void
testTortureExecute (void)
{  
#ifndef __SDCC_pdk14 // Lack of memory
  struct C c = { 0, 0, 0 };
  struct E e[2] = { { 0, &e[1] }, { 1, 0 } };
  EP p;

  foo (&c, &e[0]);
  if (c.cn != 1 || c.cp != 1)
    ASSERT (0);
  if (c.x != &e[1])
    ASSERT (0);
  if (e[1].n != &e[0])
    ASSERT (0);
  if (e[0].n)
    ASSERT (0);
  return;  
#endif
}