Skip several analyzer socket tests on hppa*-*-hpux*
[official-gcc.git] / gcc / testsuite / c-c++-common / analyzer / infinite-recursion-inlining.c
blob9dd5590acc04fc7282a6479883cd2ea6afbee6a6
1 /* A copy of infinite-recursion-2.c, to see what inlining does to the IR
2 when we see it.
4 Many cases get converted by the optimizer into iteration, and
5 into infinite loops, sometimes trivial ones.
7 Right now this is a documented limitation of the warning, but perhaps
8 could be readdressed by moving the analyzer earlier. */
10 /* { dg-additional-options "-O3" } */
12 void test_direct (void)
14 test_direct ();
15 } /* { dg-warning "infinite-loop" } */
17 void test_guarded (int flag)
19 if (flag) /* { dg-warning "infinite-loop" } */
20 test_guarded (flag);
23 void test_flipped_guard (int flag)
25 if (flag)
26 test_guarded (!flag);
29 void test_param_variant (int depth)
31 if (depth > 0)
32 test_param_variant (depth - 1);
35 void test_unguarded_param_variant (int depth)
37 test_unguarded_param_variant (depth - 1); /* { dg-warning "infinite-loop" } */
40 int g;
42 void test_global_variant ()
44 if (g-- > 0)
45 test_global_variant ();
48 /* This is a bounded recursion, as "n" is decremented before recursing... */
50 int test_while_do_predecrement_param (int n)
52 int x = 0;
53 while (n)
54 x += test_while_do_predecrement_param (--n);
55 return x;
58 /* ...whereas this one is unbounded, as "n" is decremented *after* the
59 recursive call, and so is repeatedly called with the same value. */
61 int test_while_do_postdecrement_param (int n)
63 int x = 0;
64 while (n)
65 x += test_while_do_postdecrement_param (n--); /* { dg-warning "infinite recursion" } */
66 return x;
68 /* This is a bounded recursion, as "n" is decremented before recursing... */
70 int test_do_while_predecrement_param (int n)
72 int x = 0;
74 x += test_do_while_predecrement_param (--n);
75 while (--n);
76 return x;
79 /* ...whereas this one is unbounded, as "n" is decremented *after* the
80 recursive call, and so is repeatedly called with the same value. */
82 int test_do_while_postdecrement_param (int n)
84 int x = 0;
86 x += test_do_while_postdecrement_param (n--); /* { dg-warning "infinite recursion" } */
87 while (--n);
88 return x;
91 /* Various cases of decrementing "n" as the recursion proceeds where
92 not every path recurses, but we're not actually checking "n", so
93 if "flag" is true it's an infinite recursion (which looks like an
94 infinite loop after inlining). */
96 void test_partially_guarded_postdecrement (int flag, int n)
98 if (flag) /* { dg-warning "infinite loop" } */
99 test_partially_guarded_postdecrement (flag, n--);
102 void test_partially_guarded_predecrement (int flag, int n)
104 if (flag) /* { dg-warning "infinite loop" } */
105 test_partially_guarded_predecrement (flag, --n);
108 void test_partially_guarded_subtract (int flag, int n)
110 if (flag) /* { dg-warning "infinite loop" } */
111 test_partially_guarded_subtract (flag, n - 1);