Tests for globals with different kinds of behavior in DS Analysis.
[oota-llvm.git] / test / DSGraphs / ggfuncptr.c
1 /* Test resolvable and unresolvable calls through function pointers:
2  * -- both should be retained in function graphs until resolved or until main
3  * -- former should get resolved in or before main() and never appear in GG
4  * -- latter should remain unresolved in main() and copied to GG
5  * -- globals in GG pointed to by latter should be marked I, but not other nodes
6  */
7
8 #include <stdlib.h>
9
10 extern void exit_dummy(int*);
11
12 static int X, M, Z;
13
14 void makeCalls(void(*GpKnown)(int*), void(*GpUnknown)(int*))
15 {
16   if (Z == 0) GpUnknown(&X);            /* pass to exit_dummy: never resolved */
17   else GpKnown(&M);                     /* pass to knownF: resolved in main*/
18   ++Z;
19   printf("&Z = %p\n", &Z);              /* "known external": resolved here */
20 }
21
22 void knownF(int* Y)
23 {
24   if (Y == 0) knownF(Y);                /* direct call to self: resolved here */
25 }
26
27 int main(int argc, char** argv)
28 {
29   void(*GpKnown)(int*) = knownF;
30   void(*GpUnknown)(int*) = exit_dummy;
31   Z = argc;
32   makeCalls(GpKnown, GpUnknown);
33   return 0;
34 }