https://gcc.gnu.org/bugzilla/show_bug.cgi?id=46476
--- Comment #26 from Richard Biener <rguenth at gcc dot gnu.org> ---
diff --git a/gcc/gimple-low.c b/gcc/gimple-low.c
index 18e66450977..dc56e14b605 100644
--- a/gcc/gimple-low.c
+++ b/gcc/gimple-low.c
@@ -60,7 +60,7 @@ typedef struct return_statements_t return_statements_t;
/* Helper tracking the reason a previous stmt cannot fallthru. */
struct cft_reason
{
- enum reason { CAN_FALLTHRU = false, UNKNOWN = true, RETURN };
+ enum reason { CAN_FALLTHRU = false, UNKNOWN = true, RETURN, CTRL };
cft_reason () : m_reason (CAN_FALLTHRU) {}
cft_reason (bool b) : m_reason (b ? UNKNOWN : CAN_FALLTHRU) {}
cft_reason (reason r) : m_reason (r) {}
@@ -272,6 +304,12 @@ lower_stmt (gimple_stmt_iterator *gsi, struct lower_data
*data)
warning_at (gimple_location (stmt), OPT_Wunreachable_code_return,
"statement after return is not reachable");
+ if (data->cannot_fallthru.m_reason == cft_reason::CTRL
+ && gimple_code (stmt) != GIMPLE_LABEL
+ && LOCATION_LOCUS (gimple_location (stmt)) > BUILTINS_LOCATION)
+ warning_at (gimple_location (stmt), OPT_Wunreachable_code,
+ "statement after control statement is not reachable");
+
switch (gimple_code (stmt))
{
case GIMPLE_BIND:
@@ -282,7 +320,7 @@ lower_stmt (gimple_stmt_iterator *gsi, struct lower_data
*data)
case GIMPLE_COND:
case GIMPLE_GOTO:
case GIMPLE_SWITCH:
- data->cannot_fallthru = true;
+ data->cannot_fallthru = cft_reason::CTRL;
gsi_next (gsi);
return;
would then warn about things like the following (via GIMPLE_GOTO handling),
also stmts after continue.
void baz();
void foo (int b)
{
switch (b)
{
case 1:
break;
baz ();
}
}
Looks like there's no GIMPLE stmt for throw but we have calls to __cxa_throw
so we can handle noreturn & throw here covering all throwing but not
fall thru stmts or we can match the exact ABI function being called.
As said the main issue will be premature IL eliding.