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 c/101537] -Wconversion false positive in ternary and |=
Date: Tue, 10 May 2022 08:22:45 +0000	[thread overview]
Message-ID: <bug-101537-4-zBRjJQBqyd@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-101537-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #8 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-10 branch has been updated by Jakub Jelinek
<jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:4e8c32ecfb87e723229dc6c08df8ea602e947f1e

commit r10-10666-g4e8c32ecfb87e723229dc6c08df8ea602e947f1e
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Tue Jan 11 19:11:51 2022 +0100

    c-family: Fix up -W*conversion on bitwise &/|/^ [PR101537]

    The following testcases emit a bogus -Wconversion warning.  This is because
    conversion_warning function doesn't handle BIT_*_EXPR (only
unsafe_conversion_p
    that is called during the default: case, and that one doesn't handle
    SAVE_EXPRs added because the unsigned char & or | operands promoted to int
    have side-effects and =| or =& is used.

    The patch handles BIT_IOR_EXPR/BIT_XOR_EXPR like the last 2 operands of
    COND_EXPR by recursing on the two operands, if either of them doesn't fit
    into the narrower type, complain.  BIT_AND_EXPR too, but first it needs to
    handle some special cases that unsafe_conversion_p does, namely when one
    of the two operands is a constant.

    This fixes completely the pr101537.c test and for C also pr103881.c
    and doesn't regress anything in the testsuite, for C++ pr103881.c still
    emits the bogus warnings.
    This is because while the C FE emits in that case a SAVE_EXPR that
    conversion_warning can handle already, C++ FE emits
    TARGET_EXPR <D.whatever, ...>, something | D.whatever
    etc. and conversion_warning handles COMPOUND_EXPR by "recursing" on the
    rhs.  To handle that case, we'd need for TARGET_EXPR on the lhs remember
    in some hash map the mapping from D.whatever to the TARGET_EXPR and when
    we see D.whatever, use corresponding TARGET_EXPR initializer instead.

    2022-01-11  Jakub Jelinek  <jakub@redhat.com>

            PR c/101537
            PR c/103881
    gcc/c-family/
            * c-warn.c (conversion_warning): Handle BIT_AND_EXPR, BIT_IOR_EXPR
            and BIT_XOR_EXPR.
    gcc/testsuite/
            * c-c++-common/pr101537.c: New test.
            * c-c++-common/pr103881.c: New test.

    (cherry picked from commit 20e4a5e573e76f4379b353cc736215a5f10cdb84)

  parent reply	other threads:[~2022-05-10  8:22 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-20 17:41 [Bug c++/101537] New: -Wconversion false positive in ternary me at xenu dot pl
2021-08-08 15:15 ` [Bug c++/101537] " nok.raven at gmail dot com
2021-08-12 23:47 ` [Bug c/101537] -Wconversion false positive in ternary and |= pinskia at gcc dot gnu.org
2021-12-31 17:25 ` thomas at habets dot se
2021-12-31 22:34 ` jakub at gcc dot gnu.org
2022-01-03 11:52 ` jakub at gcc dot gnu.org
2022-01-11 18:15 ` cvs-commit at gcc dot gnu.org
2022-01-24  9:21 ` cvs-commit at gcc dot gnu.org
2022-05-10  8:22 ` cvs-commit at gcc dot gnu.org [this message]
2023-06-29 15:31 ` wolter.hellmundvega at tevva dot com

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-101537-4-zBRjJQBqyd@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).