1 /*
2    pr39100.c from the execute part of the gcc torture tests.
3  */
4 
5 #include <testfwk.h>
6 
7 #ifdef __SDCC
8 #pragma std_c99
9 #pragma disable_warning 85
10 #endif
11 
12 /* Bad PTA results (incorrect store handling) was causing us to delete
13    *na = 0 store.  */
14 
15 typedef struct E
16 {
17   int p;
18   struct E *n;
19 } *EP;
20 
21 typedef struct C
22 {
23   EP x;
24   short cn, cp;
25 } *CP;
26 
27 #ifndef __SDCC_pdk14 // Lack of memory
28 CP
foo(CP h,EP x)29 foo (CP h, EP x)
30 {
31   EP pl = 0, *pa = &pl;
32   EP nl = 0, *na = &nl;
33   EP n;
34 
35   while (x)
36     {
37       n = x->n;
38       if ((x->p & 1) == 1)
39         {
40           h->cp++;
41           *pa = x;
42           pa = &((*pa)->n);
43         }
44       else
45         {
46           h->cn++;
47           *na = x;
48           na = &((*na)->n);
49         }
50       x = n;
51     }
52   *pa = nl;
53   *na = 0;
54   h->x = pl;
55   return h;
56 }
57 #endif
58 
59 void
testTortureExecute(void)60 testTortureExecute (void)
61 {
62 #ifndef __SDCC_pdk14 // Lack of memory
63   struct C c = { 0, 0, 0 };
64   struct E e[2] = { { 0, &e[1] }, { 1, 0 } };
65   EP p;
66 
67   foo (&c, &e[0]);
68   if (c.cn != 1 || c.cp != 1)
69     ASSERT (0);
70   if (c.x != &e[1])
71     ASSERT (0);
72   if (e[1].n != &e[0])
73     ASSERT (0);
74   if (e[0].n)
75     ASSERT (0);
76   return;
77 #endif
78 }
79 
80 
81