public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "msebor at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/96003] [11 Regression] spurious -Wnonnull calling a member on the result of static_cast
Date: Tue, 21 Jul 2020 20:39:20 +0000	[thread overview]
Message-ID: <bug-96003-4-JeaRefUnyp@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-96003-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #12 from Martin Sebor <msebor at gcc dot gnu.org> ---
Thanks for the test case.  In it, the no-warning bit set on the conditional
expression to avoid the warning is cleared before the expression reaches the
warning code.  The culprit seems to be the cp_fold_convert() function called on
the expression: it rebuilds the COND_EXPR but fails to propagate the no-warning
bit.  The change below fixes it but I wouldn't be surprised if this wasn't the
only instance where the no-warning bit might get stripped from an expression.

diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 300d959278b..67153e3f484 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -8754,6 +8754,7 @@ fold_unary_loc (location_t loc, enum tree_code code, tree
type, tree op0)
            arg02 = fold_build1_loc (loc, code, type,
                                 fold_convert_loc (loc,
                                                   TREE_TYPE (op0), arg02));
+         bool nowarn = TREE_NO_WARNING (op0);
          tem = fold_build3_loc (loc, COND_EXPR, type, TREE_OPERAND (arg0, 0),
                             arg01, arg02);

@@ -8788,6 +8789,8 @@ fold_unary_loc (location_t loc, enum tree_code code, tree
type, tree op0)
                                      TREE_OPERAND (TREE_OPERAND (tem, 1), 0),
                                      TREE_OPERAND (TREE_OPERAND (tem, 2),
                                                    0)));
+         if (nowarn)
+           TREE_NO_WARNING (tem) = true;
          return tem;
        }
    }

  parent reply	other threads:[~2020-07-21 20:39 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-30 11:38 [Bug tree-optimization/96003] New: Maybe a false positive for -Werror=nonnull marxin at gcc dot gnu.org
2020-06-30 11:45 ` [Bug tree-optimization/96003] " jakub at gcc dot gnu.org
2020-06-30 11:54 ` marxin at gcc dot gnu.org
2020-07-09  7:04 ` slyfox at inbox dot ru
2020-07-09 15:22 ` [Bug tree-optimization/96003] [11 Regression] " msebor at gcc dot gnu.org
2020-07-09 15:28 ` [Bug c++/96003] " msebor at gcc dot gnu.org
2020-07-09 17:40 ` slyfox at inbox dot ru
2020-07-15  6:59 ` rguenth at gcc dot gnu.org
2020-07-16  7:37 ` slyfox at inbox dot ru
2020-07-17  6:48 ` slyfox at inbox dot ru
2020-07-17 11:20 ` romain.geissler at amadeus dot com
2020-07-17 15:13 ` msebor at gcc dot gnu.org
2020-07-17 19:01 ` [Bug c++/96003] [11 Regression] spurious -Wnonnull calling a member on the result of static_cast msebor at gcc dot gnu.org
2020-07-21 19:27 ` sbergman at redhat dot com
2020-07-21 20:39 ` msebor at gcc dot gnu.org [this message]
2020-07-22 11:35 ` sbergman at redhat dot com
2020-07-30  7:36 ` marxin at gcc dot gnu.org
2020-07-30 14:30 ` msebor at gcc dot gnu.org
2020-07-31 16:29 ` cvs-commit at gcc dot gnu.org
2020-07-31 16:36 ` msebor at gcc dot gnu.org
2020-07-31 16:39 ` msebor at gcc dot gnu.org
2021-02-08  9:40 ` marxin at gcc dot gnu.org
2021-02-16 17:39 ` msebor at gcc dot gnu.org
2021-02-16 17:44 ` msebor at gcc dot gnu.org
2021-02-16 18:47 ` marxin at gcc dot gnu.org
2021-02-16 18:52 ` marxin at gcc dot gnu.org
2021-02-16 20:14 ` msebor at gcc dot gnu.org
2021-02-18  9:08 ` marxin at gcc dot gnu.org
2021-02-18  9:15 ` marxin at gcc dot gnu.org
2021-06-15 21:26 ` nyh at math dot technion.ac.il

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-96003-4-JeaRefUnyp@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).