public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "cvs-commit at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug middle-end/103597] [12 Regression] False -Wimplicit-fallthrough= involving macro since r12-5638-ga3e75c1491cd2d50
Date: Tue, 29 Mar 2022 18:11:21 +0000	[thread overview]
Message-ID: <bug-103597-4-FAZjT7ww67@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-103597-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103597

--- Comment #8 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>:

https://gcc.gnu.org/g:d886a5248e66ab911391af18bf955beb87ee8461

commit r12-7899-gd886a5248e66ab911391af18bf955beb87ee8461
Author: Marek Polacek <polacek@redhat.com>
Date:   Mon Mar 28 18:19:20 2022 -0400

    gimple: Wrong -Wimplicit-fallthrough with if(1) [PR103597]

    This patch fixes a wrong -Wimplicit-fallthrough warning for

        case 0:
          if (1)  // wrong may fallthrough
            return 0;
        case 1:

    which in .gimple looks like

        <D.1981>: // case 0
        if (1 != 0) goto <D.1985>; else goto <D.1986>;
        <D.1985>:
        D.1987 = 0;
        // predicted unlikely by early return (on trees) predictor.
        return D.1987;
        <D.1986>:  // dead
        <D.1982>: // case 1

    and the warning thinks that <D.1986>: falls through to <D.1982>:.  It
    does not know that <D.1986> is effectively a dead label, only reachable
    through fallthrough from previous instructions, never jumped to.  To
    that effect, Jakub introduced UNUSED_LABEL_P, which is set on such dead
    labels.

    collect_fallthrough_labels has code to deal with cases like

        case 2:
          if (e != 10)
            i++; // this may fallthru, warn
          else
            return 44;
        case 3:

    which collects labels that may fall through.  Here it sees the "goto
<D.1990>;"
    at the end of the then branch and so when the warning reaches

        ...
        <D.1990>: // from if-then
        <D.1984>: // case 3

    it knows it should warn about the possible fallthrough.  But an
UNUSED_LABEL_P
    is not a label that can fallthrough like that, so it should ignore those.

    However, we still want to warn about this:

        case 0:
          if (1)
            n++; // falls through
        case 1:

    so collect_fallthrough_labels needs to return the "n = n + 1;" statement,
rather
    than the dead label.

    Co-authored-by: Jakub Jelinek <jakub@redhat.com>

            PR middle-end/103597

    gcc/ChangeLog:

            * gimplify.cc (collect_fallthrough_labels): Don't push
UNUSED_LABEL_Ps
            into labels.  Maybe set prev to the statement preceding
UNUSED_LABEL_P.
            (gimplify_cond_expr): Set UNUSED_LABEL_P.
            * tree.h (UNUSED_LABEL_P): New.

    gcc/testsuite/ChangeLog:

            * c-c++-common/Wimplicit-fallthrough-39.c: New test.

  parent reply	other threads:[~2022-03-29 18:11 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-07  8:16 [Bug c++/103597] New: False -Wimplicit-fallthrough= involving macro sbergman at redhat dot com
2021-12-07  8:29 ` [Bug c++/103597] [12 Regression] False -Wimplicit-fallthrough= involving macro since r12-5638-ga3e75c1491cd2d50 marxin at gcc dot gnu.org
2021-12-07 11:24 ` jakub at gcc dot gnu.org
2021-12-07 11:33 ` pinskia at gcc dot gnu.org
2021-12-07 12:09 ` jakub at gcc dot gnu.org
2021-12-07 18:53 ` jakub at gcc dot gnu.org
2021-12-07 19:07 ` mpolacek at gcc dot gnu.org
2022-03-28 16:05 ` [Bug debug/103597] " jason at gcc dot gnu.org
2022-03-29  0:09 ` [Bug middle-end/103597] " mpolacek at gcc dot gnu.org
2022-03-29 18:11 ` cvs-commit at gcc dot gnu.org [this message]
2022-03-29 18:12 ` mpolacek at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-103597-4-FAZjT7ww67@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).