Tests for globals with different kinds of behavior in DS Analysis.
[oota-llvm.git] / test / Analysis / DSGraph / globals.c
1 /* Test globals used and unused within different parts of a program */
2
3 #include <stdlib.h>
4
5 extern void exit_dummy(int*);
6
7 static int** G;
8 static int N, M;
9
10 void
11 foo(int *Z)          /* accesses globals printf and format string, and */
12 {                    /* N = alloca(int) from test() */
13   if (Z == 0) exit_dummy(Z);            /* call to external function */
14   ++*Z;
15   printf("N = %d\n", *Z);
16 }
17
18 void leaf2(int* Y)
19 {
20   if (Y == 0) exit_dummy(Y);            /* second call to external function */
21 }
22
23 void
24 test(int* X)         /* accesses global G */
25 {                    /* allocates G = malloc(int*) and N = alloca(int) */
26   if (X == 0)
27     X = &N;
28   G = (int**) alloca(sizeof(int*));
29   *G = &N;
30   **G = 10;
31   foo(*G);
32   leaf2(*G);
33   *X = **G;
34   /* free(G); */
35 }
36
37 int
38 main()               /* only accesses global N */
39 {
40   /* N = 0; */
41   test(0 /*&N*/);
42   return 0;
43 }