1 /* { dg-do run } */
2 
3 __attribute__((__noipa__))
f1(int x,void (* p1[])(int,int))4 void f1(int x, void (*p1 []) (int, int))
5 {
6   int i;
7   for (i = 0; i < x; i++)
8     p1[i](42, 666);
9 }
10 
11 int z1_called = 0;
12 int w1_called = 0;
13 
14 __attribute__((__noipa__))
z1(int a,int b)15 void z1(int a, int b)
16 {
17   if (w1_called || z1_called)
18     __builtin_abort();
19   z1_called++;
20 }
21 
22 __attribute__((__noipa__))
w1(int a,int b)23 void w1(int a, int b)
24 {
25   if (w1_called || !z1_called)
26     __builtin_abort();
27   w1_called++;
28 }
29 
30 int z2_called = 0;
31 int w2_called = 0;
32 
33 __attribute__((__noipa__))
z2(void)34 void z2(void)
35 {
36   if (w2_called || z2_called)
37     __builtin_abort();
38   z2_called++;
39 }
40 
41 __attribute__((__noipa__))
w2(void)42 void w2(void)
43 {
44   if (w2_called || !z2_called)
45     __builtin_abort();
46   w2_called++;
47 }
48 
49 void (*p2 []) () = { w2, z2 };
50 
51 __attribute__((__noipa__))
f2(int x)52 void f2(int x)
53 {
54   void (**q) (void) = p2 + x;
55   int i;
56   for (i = 0; i < x; i++)
57     (*(--q))();
58 }
59 
60 __attribute__((__noipa__))
f3(int x,int (* p3[])(int))61 void f3(int x, int (*p3 []) (int))
62 {
63   int i;
64   int next = x;
65   for (i = 0; i < x; i++)
66     next = p3[i](next);
67 }
68 
69 int z3_called = 0;
70 int w3_called = 0;
71 
72 __attribute__((__noipa__))
z3(int a)73 int z3(int a)
74 {
75   if (w3_called || z3_called || a != 2)
76     __builtin_abort();
77   z3_called++;
78   return 42;
79 }
80 
81 __attribute__((__noipa__))
w3(int a)82 int w3(int a)
83 {
84   if (w3_called || !z3_called || a != 42)
85     __builtin_abort();
86   w3_called++;
87   return 4096;
88 }
89 
90 int (*p4 []) (int) = { z3, w3 };
91 
92 __attribute__((__noipa__))
f4(int x)93 void f4(int x)
94 {
95   int (**q) (int) = p4;
96   int (**r) (int) = p4 + x;
97 
98   int next = x;
99   for (; q < r; q++)
100     next = (*q)(next);
101 }
102 
main(void)103 int main(void)
104 {
105   static int (*p3 []) (int) = { z3, w3 };
106 
107   static void (*p1 []) (int, int) = { z1, w1 };
108 
109   f1(2, p1);
110   if (z1_called != 1 || w1_called != 1)
111     __builtin_abort();
112 
113   f2(2);
114   if (z2_called != 1 || w2_called != 1)
115     __builtin_abort();
116 
117   f3(2, p3);
118   if (z3_called != 1 || w3_called != 1)
119     __builtin_abort();
120 
121   z3_called = 0;
122   w3_called = 0;
123   f4(2);
124   if (z3_called != 1 || w3_called != 1)
125     __builtin_abort();
126 
127   __builtin_exit(0);
128 }
129