From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 33851 invoked by alias); 5 Oct 2016 16:53:01 -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 33838 invoked by uid 89); 5 Oct 2016 16:53:00 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.5 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= 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; Wed, 05 Oct 2016 16:52:59 +0000 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (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 13CBD46E for ; Wed, 5 Oct 2016 16:52:58 +0000 (UTC) Received: from redhat.com (ovpn-204-26.brq.redhat.com [10.40.204.26]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u95GqtNa031833 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Wed, 5 Oct 2016 12:52:57 -0400 Date: Wed, 05 Oct 2016 16:53:00 -0000 From: Marek Polacek To: GCC Patches Subject: Re: Fix missing -Wimplicit-fallthrough warning Message-ID: <20161005165254.GV3223@redhat.com> References: <20160929161027.GT3223@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20160929161027.GT3223@redhat.com> User-Agent: Mutt/1.7.0 (2016-08-17) X-SW-Source: 2016-10/txt/msg00296.txt.bz2 Ping. On Thu, Sep 29, 2016 at 06:10:27PM +0200, Marek Polacek wrote: > Here, a missing -Wimplicit-fallthrough warning was caused by a misplaced > FALLTHROUGH_LABEL_P check. As it is now, for FALLTHROUGH_LABEL_P we'd > never gotten around to > 1933 /* So that next warn_implicit_fallthrough_r will start looking for > 1934 a new sequence starting with this label. */ > 1935 gsi_prev (gsi_p); > > The fix is to move the check to should_warn_for_implicit_fallthrough. > > Bootstrapped/regtested on x86_64-linux and ppc64-linux, ok for trunk? > > 2016-09-29 Marek Polacek > > * gimplify.c (should_warn_for_implicit_fallthrough): Check for > FALLTHROUGH_LABEL_P here... > (warn_implicit_fallthrough_r): ...not here. > > * c-c++-common/Wimplicit-fallthrough-22.c: New test. > > diff --git gcc/gimplify.c gcc/gimplify.c > index 66bb8be..e077a7e 100644 > --- gcc/gimplify.c > +++ gcc/gimplify.c > @@ -1817,6 +1817,10 @@ should_warn_for_implicit_fallthrough (gimple_stmt_iterator *gsi_p, tree label) > { > gimple_stmt_iterator gsi = *gsi_p; > > + /* Don't warn if the label is marked with a "falls through" comment. */ > + if (FALLTHROUGH_LABEL_P (label)) > + return false; > + > /* Don't warn for a non-case label followed by a statement: > case 0: > foo (); > @@ -1903,7 +1907,6 @@ warn_implicit_fallthrough_r (gimple_stmt_iterator *gsi_p, bool *handled_ops_p, > if (gimple_code (next) == GIMPLE_LABEL > && gimple_has_location (next) > && (label = gimple_label_label (as_a (next))) > - && !FALLTHROUGH_LABEL_P (label) > && prev != NULL) > { > struct label_entry *l; > diff --git gcc/testsuite/c-c++-common/Wimplicit-fallthrough-22.c gcc/testsuite/c-c++-common/Wimplicit-fallthrough-22.c > index e69de29..7a81e47 100644 > --- gcc/testsuite/c-c++-common/Wimplicit-fallthrough-22.c > +++ gcc/testsuite/c-c++-common/Wimplicit-fallthrough-22.c > @@ -0,0 +1,23 @@ > +/* { dg-do compile } */ > +/* { dg-options "-Wimplicit-fallthrough" } */ > + > +void bar (int); > + > +void > +foo (int i) > +{ > + switch (i) > + { > + case 1: > + bar (1); > + /* FALLTHROUGH */ > + case 2: > + bar (2); /* { dg-warning "statement may fall through" } */ > + case 3: > + bar (3); /* { dg-warning "statement may fall through" } */ > + case 4: > + bar (4); > + default: > + break; > + } > +} > > Marek Marek