aboutsummaryrefslogtreecommitdiff
path: root/test/Analysis/DSGraph/globals.c
blob: fc8f87c6d925ee66bfa7d1989c3d18f669afac5e (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
/* Test globals used and unused within different parts of a program */

/* FIXME: This testcase should be automated */

#include <stdlib.h>

extern void exit_dummy(int*);

static int** G;
static int N, M;

void
foo(int *Z)          /* accesses globals printf and format string, and */
{                    /* N = alloca(int) from test() */
  if (Z == 0) exit_dummy(Z);            /* call to external function */
  ++*Z;
  printf("N = %d\n", *Z);
}

void leaf2(int* Y)
{
  if (Y == 0) exit_dummy(Y);            /* second call to external function */
}

void
test(int* X)         /* accesses global G */
{                    /* allocates G = malloc(int*) and N = alloca(int) */
  if (X == 0)
    X = &N;
  G = (int**) alloca(sizeof(int*));
  *G = &N;
  **G = 10;
  foo(*G);
  leaf2(*G);
  *X = **G;
  /* free(G); */
}

int
main()               /* only accesses global N */
{
  /* N = 0; */
  test(0 /*&N*/);
  return 0;
}