From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 0036B3858435; Fri, 26 Nov 2021 10:04:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0036B3858435 From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/46476] Missing Warning about unreachable code after return [-Wunreachable-code-return] Date: Fri, 26 Nov 2021 10:04:22 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 4.6.0 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: enhancement X-Bugzilla-Who: rguenth at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: rguenth at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: attachments.created Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 26 Nov 2021 10:04:23 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D46476 --- Comment #25 from Richard Biener --- Created attachment 51878 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D51878&action=3Dedit -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.=