On 11/26/2021 5:18 AM, Richard Biener via Gcc-patches wrote:
This implements a subset of -Wunreachable-code, unreachable code
after a return stmt.  Contrary to the previous attemt at CFG
construction time this implements the bits during GIMPLE lowering
where there are still all GIMPLE return stmts in the IL.

The lowering phase keeps track of whether stmts can fallthru
which is used to determine if the following stmt is reachable.
The implementation only considers labels here.

The fallthru flag is transparently extended to allow tracking
a reason for non-fallthruness which is used to mark returns.

This patch runs in to the same stray return/gcc_unreachable as the
previous one and thus requires cleanup across the GCC code base
which seems controversical.  So I'm putting this on hold unless
I receive some OK for cleanup in any way, meaning this isn't
going to make stage3.

Sorry.

Richard.

2021-11-26  Richard Biener  <rguent...@suse.de>

        PR c++/46476
gcc/cp/
        * decl.c (finish_function): Set input_location to
        BUILTINS_LOCATION around the code building the return 0
        for main().
        * cp-gimplify.c (genericize_if_stmt): Avoid optimizing if (true)
        and if (false) when -Wunreachable-code-return is in effect.

gcc/
        * common.opt (Wunreachable-code): Re-enable.
        (Wunreachable-code-return): New diagnostic, enabled by
        -Wextra and -Wunreachable-code.
        * doc/invoke.texi (Wunreachable-code): Document.
        (Wunreachable-code-return): Likewise.
        * gimple-low.c: Include diagnostic.h.
        (struct cft_reason): New.
        (lower_data::cannot_fallthru): Make a cft_reason.
        (lower_stmt): Diagnose unreachable stmts after a return.
        * Makefile.in (insn-emit.o-warn): Disable
        -Wunreachable-code-return.

gcc/testsuite/
        * c-c++-common/Wunreachable-code-return-1.c: New testcase.
I wouldn't object to this moving forward.  I've already ACK'd the cleanups.

Jeff

Reply via email to