From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1314) id 6C1FD3858D39; Wed, 25 Aug 2021 21:28:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6C1FD3858D39 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Andrew Pinski To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-3145] Fix PR c++/66590: incorrect warning "reaches end of non-void function" for switch X-Act-Checkin: gcc X-Git-Author: Andrew Pinski X-Git-Refname: refs/heads/trunk X-Git-Oldrev: ed3de423f1694d30f9cccc0c024fb6e19e2c6323 X-Git-Newrev: 971df602e0a798fe9c805c3105f4ac80d638a12b Message-Id: <20210825212840.6C1FD3858D39@sourceware.org> Date: Wed, 25 Aug 2021 21:28:40 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 25 Aug 2021 21:28:40 -0000 https://gcc.gnu.org/g:971df602e0a798fe9c805c3105f4ac80d638a12b commit r12-3145-g971df602e0a798fe9c805c3105f4ac80d638a12b Author: Andrew Pinski Date: Mon Aug 9 18:33:17 2021 -0700 Fix PR c++/66590: incorrect warning "reaches end of non-void function" for switch So the problem here is there is code in the C++ front-end not to add a break statement (to the IR) if the previous block does not fall through. The problem is the code which does the check to see if the block may fallthrough does not check a CLEANUP_STMT; it assumes it is always fall through. Anyways this adds the code for the case of a CLEANUP_STMT that is only for !CLEANUP_EH_ONLY (the try/finally case). OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. gcc/cp/ChangeLog: PR c++/66590 * cp-objcp-common.c (cxx_block_may_fallthru): Handle CLEANUP_STMT for the case which will be try/finally. gcc/testsuite/ChangeLog: PR c++/66590 * g++.dg/warn/Wreturn-5.C: New test. Diff: --- gcc/cp/cp-objcp-common.c | 9 +++++++++ gcc/testsuite/g++.dg/warn/Wreturn-5.C | 15 +++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/gcc/cp/cp-objcp-common.c b/gcc/cp/cp-objcp-common.c index 98fd96227c4..28f2d7bee71 100644 --- a/gcc/cp/cp-objcp-common.c +++ b/gcc/cp/cp-objcp-common.c @@ -317,6 +317,15 @@ cxx_block_may_fallthru (const_tree stmt) return true; return block_may_fallthru (ELSE_CLAUSE (stmt)); + case CLEANUP_STMT: + /* Just handle the try/finally cases. */ + if (!CLEANUP_EH_ONLY (stmt)) + { + return (block_may_fallthru (CLEANUP_BODY (stmt)) + && block_may_fallthru (CLEANUP_EXPR (stmt))); + } + return true; + default: return c_block_may_fallthru (stmt); } diff --git a/gcc/testsuite/g++.dg/warn/Wreturn-5.C b/gcc/testsuite/g++.dg/warn/Wreturn-5.C new file mode 100644 index 00000000000..543e33e905d --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wreturn-5.C @@ -0,0 +1,15 @@ +// PR C++/66590 +// { dg-do compile } +// { dg-options "-Wall" } + +struct A{ ~A();}; + +int f(int x) +{ + A a; + switch (x) + { + case 1: { A tmp; return 1; } break; + default: return 0; + } +} // { dg-bogus "control reaches end of non-void function" }