/* A copy of infinite-recursion-2.c, to see what inlining does to the IR when we see it. Many cases get converted by the optimizer into iteration, and into infinite loops, sometimes trivial ones. Right now this is a documented limitation of the warning, but perhaps could be readdressed by moving the analyzer earlier. */ /* { dg-additional-options "-O3" } */ void test_direct (void) { test_direct (); } /* { dg-warning "infinite-loop" } */ void test_guarded (int flag) { if (flag) /* { dg-warning "infinite-loop" } */ test_guarded (flag); } void test_flipped_guard (int flag) { if (flag) test_guarded (!flag); } void test_param_variant (int depth) { if (depth > 0) test_param_variant (depth - 1); } void test_unguarded_param_variant (int depth) { test_unguarded_param_variant (depth - 1); /* { dg-warning "infinite-loop" } */ } int g; void test_global_variant () { if (g-- > 0) test_global_variant (); } /* This is a bounded recursion, as "n" is decremented before recursing... */ int test_while_do_predecrement_param (int n) { int x = 0; while (n) x += test_while_do_predecrement_param (--n); return x; } /* ...whereas this one is unbounded, as "n" is decremented *after* the recursive call, and so is repeatedly called with the same value. */ int test_while_do_postdecrement_param (int n) { int x = 0; while (n) x += test_while_do_postdecrement_param (n--); /* { dg-warning "infinite recursion" } */ return x; } /* This is a bounded recursion, as "n" is decremented before recursing... */ int test_do_while_predecrement_param (int n) { int x = 0; do x += test_do_while_predecrement_param (--n); while (--n); return x; } /* ...whereas this one is unbounded, as "n" is decremented *after* the recursive call, and so is repeatedly called with the same value. */ int test_do_while_postdecrement_param (int n) { int x = 0; do x += test_do_while_postdecrement_param (n--); /* { dg-warning "infinite recursion" } */ while (--n); return x; } /* Various cases of decrementing "n" as the recursion proceeds where not every path recurses, but we're not actually checking "n", so if "flag" is true it's an infinite recursion (which looks like an infinite loop after inlining). */ void test_partially_guarded_postdecrement (int flag, int n) { if (flag) /* { dg-warning "infinite loop" } */ test_partially_guarded_postdecrement (flag, n--); } void test_partially_guarded_predecrement (int flag, int n) { if (flag) /* { dg-warning "infinite loop" } */ test_partially_guarded_predecrement (flag, --n); } void test_partially_guarded_subtract (int flag, int n) { if (flag) /* { dg-warning "infinite loop" } */ test_partially_guarded_subtract (flag, n - 1); }