public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "mkretz at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/38470] value range propagation (VRP) would improve -Wsign-compare
Date: Mon, 28 Jun 2021 15:07:14 +0000	[thread overview]
Message-ID: <bug-38470-4-mddeEW4hfy@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-38470-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #29 from Matthias Kretz (Vir) <mkretz at gcc dot gnu.org> ---
(In reply to Vincent Lefèvre from comment #28)
> (In reply to Matthias Kretz (Vir) from comment #27)
> > Fair enough. But how can the compiler be certain that the developer realized
> > u and u % 100 is unsigned? Maybe when (s)he wrote the code the expectation
> > was for the RHS to be within [-99..99].
> 
> Indeed. (I never use % when its LHS can be either positive or negative, so
> that I didn't think about this case.)

FWIW, personally I could use a warning whenever I use % on variables that can
potentially be negative. Because my mental model of % N is that I get a result
in [0..N-1]. I tried to fix it but my head is stubborn. ;)

> Now, the cause of the bug in such a case would be that the user messed up
> with the signedness of u, not because he forgot about the promotion rule.
> This is something rather different.

Right. But if that's the case wouldn't a warning about the unexpected promotion
be useful? (which -Wsign-compare happens to provide)

To reduce the noise, I won't argue this point any further and let whoever
actually implements a fix for the PR decide. :)

  parent reply	other threads:[~2021-06-28 15:07 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <bug-38470-4@http.gcc.gnu.org/bugzilla/>
2011-06-15 18:16 ` manu at gcc dot gnu.org
2012-03-24  7:50 ` DeusExSophismata at gmail dot com
2012-04-16 10:44 ` manu at gcc dot gnu.org
2013-05-20 13:23 ` paolo.carlini at oracle dot com
2015-01-07 11:11 ` manu at gcc dot gnu.org
2015-06-22 10:41 ` manu at gcc dot gnu.org
2020-05-06  8:45 ` kretz at kde dot org
2020-05-06  8:46 ` kretz at kde dot org
2020-11-03  4:14 ` egallager at gcc dot gnu.org
2021-06-28 13:01 ` inkerman42 at gmail dot com
2021-06-28 13:51 ` mkretz at gcc dot gnu.org
2021-06-28 14:13 ` vincent-gcc at vinc17 dot net
2021-06-28 14:30 ` mkretz at gcc dot gnu.org
2021-06-28 14:53 ` vincent-gcc at vinc17 dot net
2021-06-28 15:07 ` mkretz at gcc dot gnu.org [this message]
2021-06-28 15:33 ` vincent-gcc at vinc17 dot net
2008-12-10 10:35 [Bug c/38470] New: Feature request: smarter signed/unsigned warning m dot j dot thayer at googlemail dot com
2010-02-24 14:11 ` [Bug c/38470] value range propagation (VRP) would improve -Wsign-compare manu at gcc dot gnu dot org
2010-02-24 14:13 ` manu at gcc dot gnu dot org
2010-02-24 14:17 ` m dot j dot thayer at googlemail 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-38470-4-mddeEW4hfy@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).