https://gcc.gnu.org/bugzilla/show_bug.cgi?id=46476

--- Comment #25 from Richard Biener <rguenth at gcc dot gnu.org> ---
Created attachment 51878
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=51878&action=edit
-Wunreachable-code-return at GIMPLE lowering time

This is an alternative change only implementing -Wunreachable-code-return
(-Wunreachable-code-throw should be doable within this framework as well).

It does so during GIMPLE lowering where we still have return stmts using
the can_fallthru logic already present.

The approach has the same issues with premature optimization by the C++
frontend
eliding if (0) and if (1) as shown during bootstrap so the relevant hunk is
included here, too, likewise the double return in main().

It also warns for

void baz();
void foo (int b)
{
  if (b)
    __builtin_abort ();
  else
    return;
  baz ();
}

but not for

void baz();
void foo (int b)
{
  if (b)
    return;
  else
    __builtin_abort ();
  baz ();
}

as the previous stmt here is not the return but the abort() but in both
cases baz () is not really "after return" but after an if, but that part
of the IL structure is not easily visible.  For the same reason
implementing -Wunreachable-code-break as supported by clang is difficult
(break is just a goto in GIMPLE).

At least this patch passes bootstrap and would have found one real issue
but not the problematic dead "looping" stmts.

Reply via email to