aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.9/gcc/testsuite/gcc.dg/tree-ssa/pr36908.c
blob: 8fa2ed2ca1f80a73a819a507d1750d238cd5e7c0 (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
/* { dg-do compile } */
/* { dg-options "-O2 -ftree-loop-distribution" } */
#define NULL ((void *)0)

__extension__ typedef __SIZE_TYPE__ size_t;
extern void *foo(size_t nelem, size_t elsize);
extern void bar (char*, ...);

typedef struct alt_state *alt_state_t;
typedef struct state *state_t;

struct alt_state
{
  alt_state_t next_alt_state;
};

static alt_state_t first_free_alt_state = NULL;

static void
free_alt_state (alt_state_t alt_state)
{
  if (alt_state == NULL)
    return;
  alt_state->next_alt_state = first_free_alt_state;
  first_free_alt_state = alt_state;
}

/* The function frees list started with node ALT_STATE_LIST.  */
static void
free_alt_states (alt_state_t alt_states_list)
{
  alt_state_t curr_alt_state;
  alt_state_t next_alt_state;

  for (curr_alt_state = alt_states_list;
       curr_alt_state != NULL;
       curr_alt_state = next_alt_state)
    {
      next_alt_state = curr_alt_state->next_alt_state;
      free_alt_state (curr_alt_state);
    }
}

int 
main (void)
{
  int i;
  alt_state_t state, act_state;

  act_state = state = foo (1, sizeof (struct alt_state));
  for (i = 0; i < 2; i ++)
  {
    act_state->next_alt_state = foo (1, sizeof (struct alt_state));
    act_state = act_state->next_alt_state;
  }

  free_alt_states (state);

  for (act_state = first_free_alt_state;
       act_state != NULL;
       act_state = act_state->next_alt_state)
       bar ("going from %p to %p\n", act_state, act_state->next_alt_state);

  return 0;
}