public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "jakub at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/102291] [9/10/11/12 Regression] wrong overflow warning for compound expression conversion and bit_and expressions
Date: Mon, 06 Dec 2021 14:07:58 +0000	[thread overview]
Message-ID: <bug-102291-4-3twC4oG2De@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-102291-4@http.gcc.gnu.org/bugzilla/>

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jason at gcc dot gnu.org,
                   |                            |jsm28 at gcc dot gnu.org,
                   |                            |mpolacek at gcc dot gnu.org

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
I'm afraid I'm getting lost in what convert does though with the TREE_OVERFLOW
flag.
In the testcase, we have a cast of BIT_IOR_EXPR with (whatever, 0x80) and 0 int
arguments to unsigned char.
do_narrow is called and does:
      /* Don't do unsigned arithmetic where signed was wanted,
         or vice versa.
         Exception: if both of the original operands were
         unsigned then we can safely do the work as unsigned.
         Exception: shift operations take their type solely
         from the first argument.
         Exception: the LSHIFT_EXPR case above requires that
         we perform this operation unsigned lest we produce
         signed-overflow undefinedness.
         And we may need to do it as unsigned
         if we truncate to the original size.  */
and as BIT_IOR_EXPR isn't listed, type == typex is unsigned and TREE_TYPE
(arg0) and TREE_TYPE (arg1) are signed goes the:
          if (TYPE_UNSIGNED (typex))
            typex = signed_type_for (typex);
way.  Those conversions create TYPE_OVERFLOW constant, even when there was
nothing wrong in the source and because of the COMPOUND_EXPRs in there we don't
manage to optimize those TYPE_OVERFLOW constants away and warn on it.

For BIT_AND_EXPR/BIT_IOR_EXPR/BIT_XOR_EXPR, I must say I miss the reason why
it would be ever a good idea to use typex = signed_type_for (typex), when we
want unsigned result, just converting to that right away doesn't have any
downsides I can come up with.
But I wonder even about the other operations, do we really want to introduce
TYPE_OVERFLOWs in such cases where the operations are originally on wider
signed operands and are cast to some narrower unsigned type?

  parent reply	other threads:[~2021-12-06 14:07 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-11 15:43 [Bug c/102291] New: dubious overflow warning hv at crypt dot org
2021-09-11 19:33 ` [Bug c/102291] [9/10/11/12 Regression] wrong overflow warning for compound expression conversion and bit_and expressions pinskia at gcc dot gnu.org
2021-09-11 19:33 ` pinskia at gcc dot gnu.org
2021-09-11 19:36 ` pinskia at gcc dot gnu.org
2021-12-06 12:46 ` jakub at gcc dot gnu.org
2021-12-06 14:07 ` jakub at gcc dot gnu.org [this message]
2021-12-06 16:03 ` jakub at gcc dot gnu.org
2021-12-06 16:09 ` jakub at gcc dot gnu.org
2021-12-06 22:44 ` joseph at codesourcery dot com
2022-01-20 10:02 ` rguenth at gcc dot gnu.org
2022-05-27  9:46 ` [Bug c/102291] [10/11/12/13 " rguenth at gcc dot gnu.org
2022-06-28 10:46 ` jakub at gcc dot gnu.org
2023-07-07 10:40 ` [Bug c/102291] [11/12/13/14 " rguenth 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-102291-4-3twC4oG2De@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).