Constant fold the isnan intrinsic
[oota-llvm.git] / test / Analysis / DSGraph / globalgraph.c
1 /* FIXME: this testcase should be automated! */
2
3 #include <stdio.h>
4
5 typedef struct Tree_struct {
6   int data;
7   struct Tree_struct *left, *right;
8 } Tree;
9
10 static Tree T1, T2, T3, T4, T5, T6, T7;
11 static Tree *Root, *ANode;
12 static int  N = 4107;
13
14 /* forces *Tb->right to be collapsed */
15 void makeMore(Tree* Ta, Tree* Tb)
16 {
17   Ta->left  = &T1;
18   Ta->right = &T2;
19   Tb->left  = &T4;
20   /* Tb->right = &T5; */
21   Tb->right = (Tree*) (((char*) &T5) + 5); /* point to fifth byte of T5 */
22 }
23
24 /* multiple calls to this should force globals to be merged in TD graph
25  * but not in globals graph
26  */
27 void makeData(Tree* Ta)
28 {
29   static int N = 101;
30   Ta->data = N;
31 }
32
33 void makeRoots()
34 {
35   T1.left = &T2;
36   makeMore(&T1, &T3);
37 }
38
39 /* BU graph shows T1.left->{T2}, but TD graph should show T1.left->{T1,T2,T6,H}
40  * and T.right->{T1,T2,T6,H} */
41 void makeAfter1()
42 {
43   T1.left = &T2;
44 }
45
46 /* BU graph shows:
47  *      T2.right->{H}, H.left->{T6}; H.right->{T2}, T3.left<->T7.left
48  * 
49  * TD graph and GlobalsGraph should show:
50  *      T2.right->{T1,T2,T6,H}
51  *      H.left->{T1,T2,T6,H}; H.right->{T1,T2,T6,H}.
52  *      T3.left->{T4,T7}, T3.right->{T4,T7}, T7.left->{T3}
53  */
54 void makeAfter2()
55 {
56   Tree* newT  = (Tree*) malloc(sizeof(Tree));
57   T2.right    = newT;                   /* leaked: do not access T2 in main */
58   newT->left  = &T6;
59   newT->right = &T2;
60
61   T3.left     = &T7;
62   T7.left     = &T3;
63 }
64
65 /* BU and TD graphs should have no reachable globals, forcing callers and
66  * callees to get all globals from GlobalsGraph
67  */
68 void makePass()
69 {
70   makeAfter1();
71   makeAfter2();
72 }
73
74 int main()
75 {
76   makeRoots();
77   T3.right = &T4;
78   makeData(&T3);
79   makeData(&T5);
80   makePass();
81   printf("T3.data = %d\n", T3.data);
82 }