Imported Upstream version 4.8.1
[platform/upstream/gcc48.git] / gcc / testsuite / gcc.dg / ipa / iinline-4.c
1 /* Verify that simple indirect calls are inlined even without early
2    inlining..  */
3 /* { dg-do compile } */
4 /* { dg-options "-O3 -fdump-ipa-inline -fno-early-inlining"  } */
5
6 struct S
7 {
8   int i;
9   void (*f)(struct S *);
10   unsigned u;
11 };
12
13 struct U
14 {
15   struct U *next;
16   struct S s;
17   short a[8];
18 };
19
20 extern void non_existent(struct S *p, int);
21
22 /* ----- 1 ----- */
23
24 static void hooray1 (struct S *p)
25 {
26   non_existent (p, 1);
27 }
28
29 static void hiphip1 (struct S *p)
30 {
31   p->f (p);
32 }
33
34 int test1 (void)
35 {
36   struct S s;
37   s.i = 1234;
38   s.f = hooray1;
39   s.u = 1001;
40   hiphip1 (&s);
41   return 0;
42 }
43
44 /* ----- 2 ----- */
45
46 struct S *gp;
47
48 static void hooray2 (struct S *p)
49 {
50   non_existent (p, 2);
51 }
52
53 static void hip2 (struct S *p)
54 {
55   p->f (p);
56 }
57
58 static void hiphip2 (struct S *p)
59 {
60   hip2 (p);
61 }
62
63 int test2 (void)
64 {
65   struct S *p = gp;
66   p->i = 2341;
67   p->f = hooray2;
68   p->u = 1002;
69   hiphip2 (p);
70   return 0;
71 }
72
73 /* ----- 3 ----- */
74
75 static void hooray3 (struct S *p)
76 {
77   non_existent (p, 2);
78 }
79
80 static void hip3 (struct S *p)
81 {
82   p->f (p);
83 }
84
85 static __attribute__ ((flatten)) void hiphip3 (struct S *p)
86 {
87   hip3 (p);
88 }
89
90 int test3 (void)
91 {
92   struct S *p = gp;
93   p->i = 2341;
94   p->f = hooray3;
95   p->u = 1003;
96   hiphip3 (p);
97   return 0;
98 }
99
100 /* ----- 4 ----- */
101
102 static void hooray4 (struct S *p)
103 {
104   non_existent (p, 3);
105 }
106
107 static void hiphip4 (struct S s)
108 {
109   s.f (&s);
110 }
111
112 int test4(void)
113 {
114   struct S s;
115   s.i = 3412;
116   s.f = hooray4;
117   s.u = 1004;
118   hiphip4 (s);
119   return 0;
120 }
121
122 /* ----- 5 ----- */
123
124 struct U *gu;
125
126 static void hooray5 (struct S *p)
127 {
128   non_existent (p, 5);
129 }
130
131 static void hip5 (struct S *p)
132 {
133   p->f (p);
134 }
135
136 static void hiphip5 (struct U *u)
137 {
138   hip5 (&u->s);
139 }
140
141 int test5 (void)
142 {
143   struct U *u = gu;
144   u->next = u;
145   u->s.i = 9876;
146   u->s.f = hooray5;
147   u->s.u = 1005;
148   hiphip5 (u);
149   return 0;
150 }
151
152 /* ----- 6 ----- */
153
154 static void hooray6 (struct S *p)
155 {
156   non_existent (p, 6);
157 }
158
159 static void hip6 (struct S *p)
160 {
161   p->f (p);
162 }
163
164 static __attribute__ ((flatten)) void hiphip6 (struct U *u)
165 {
166   hip6 (&u->s);
167 }
168
169 int test6 (void)
170 {
171   struct U *u = gu;
172   u->next = u;
173   u->s.i = 9876;
174   u->s.f = hooray6;
175   u->s.u = 1006;
176   hiphip6 (u);
177   return 0;
178 }
179
180 /* ----- 7 ----- */
181
182 struct S **gdp;
183
184
185 static void hooray7 (struct S *p)
186 {
187   non_existent (p, 7);
188 }
189
190 static void hip7 (struct S *p)
191 {
192   p->f (p);
193   gdp = &p;
194 }
195
196 static void hiphip7 (struct S *p)
197 {
198   hip7 (p);
199   gdp = &p;
200 }
201
202 int test7 (void)
203 {
204   struct S *p = gp;
205   p->i = 7341;
206   p->f = hooray7;
207   p->u = 1007;
208   hiphip7 (p);
209   return 0;
210 }
211
212
213
214 /* { dg-final { scan-ipa-dump "hooray1\[^\\n\]*inline copy in test1"  "inline"  } } */
215 /* { dg-final { scan-ipa-dump "hooray2\[^\\n\]*inline copy in test2"  "inline"  } } */
216 /* { dg-final { scan-ipa-dump "hooray3\[^\\n\]*inline copy in test3"  "inline"  } } */
217 /* { dg-final { scan-ipa-dump "hooray4\[^\\n\]*inline copy in test4"  "inline"  { xfail { { hppa*-*-* } && { ! lp64 } } } } } */
218 /* { dg-final { scan-ipa-dump "hooray5\[^\\n\]*inline copy in test5"  "inline"  } } */
219 /* { dg-final { scan-ipa-dump "hooray6\[^\\n\]*inline copy in test6"  "inline"  } } */
220 /* { dg-final { scan-ipa-dump "hooray7\[^\\n\]*inline copy in test7"  "inline"  } } */
221 /* { dg-final { cleanup-ipa-dump "inline" } } */