From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14603 invoked by alias); 30 Sep 2016 21:31:57 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 14485 invoked by uid 89); 30 Sep 2016 21:31:56 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.9 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=1687,7, 16877 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 30 Sep 2016 21:31:55 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C2610283F2E for ; Fri, 30 Sep 2016 21:31:53 +0000 (UTC) Received: from redhat.com (ovpn-204-20.brq.redhat.com [10.40.204.20]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u8ULVo0v030171 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Fri, 30 Sep 2016 17:31:53 -0400 Date: Fri, 30 Sep 2016 21:39:00 -0000 From: Marek Polacek To: GCC Patches Subject: PATCH to fix bogus -Wimplicit-fallthrough warning (PR c++/77803) Message-ID: <20160930213150.GH3223@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.7.0 (2016-08-17) X-SW-Source: 2016-09/txt/msg02432.txt.bz2 This PR reports a bogus -Wimplicit-fallthrough warning on the attached test. The problem is that last_stmt_in_scope should for GIMPLE_TRY, if the last statement of the eval part can't fallthrough, return this statement and don't warn. And the same should be true for FALLTHROUGH (). This patch fixes it. Bootstrapped/regtested on x86_64-linux, ok for trunk? 2016-09-30 Marek Polacek PR c++/77803 * gimplify.c (last_stmt_in_scope): Add check for FALLTHROUGH (). * g++.dg/warn/Wimplicit-fallthrough-1.C: New test. diff --git gcc/gimplify.c gcc/gimplify.c index 66bb8be..97d63db 100644 --- gcc/gimplify.c +++ gcc/gimplify.c @@ -1687,6 +1687,7 @@ last_stmt_in_scope (gimple *stmt) stmt = gimple_seq_last_stmt (gimple_try_eval (try_stmt)); gimple *last_eval = last_stmt_in_scope (stmt); if (gimple_stmt_may_fallthru (last_eval) + && !gimple_call_internal_p (last_eval, IFN_FALLTHROUGH) && gimple_try_kind (try_stmt) == GIMPLE_TRY_FINALLY) { stmt = gimple_seq_last_stmt (gimple_try_cleanup (try_stmt)); diff --git gcc/testsuite/g++.dg/warn/Wimplicit-fallthrough-1.C gcc/testsuite/g++.dg/warn/Wimplicit-fallthrough-1.C index e69de29..8f80b01 100644 --- gcc/testsuite/g++.dg/warn/Wimplicit-fallthrough-1.C +++ gcc/testsuite/g++.dg/warn/Wimplicit-fallthrough-1.C @@ -0,0 +1,16 @@ +// PR c++/77803 +// { dg-do compile { target c++11 } } +// { dg-options "-Wimplicit-fallthrough" } + +struct A {}; +int a; +void fn1() { + switch (0) { + case 0: { + A b; + [[fallthrough]]; + } + default: + a = 0; + } +} Marek