public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/101645] New: -Wsign-conversion misses negation of unsigned int
@ 2021-07-27 15:21 matthew at wil dot cx
  2021-07-27 15:27 ` [Bug c/101645] " jrtc27 at jrtc27 dot com
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: matthew at wil dot cx @ 2021-07-27 15:21 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 101645
           Summary: -Wsign-conversion misses negation of unsigned int
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: matthew at wil dot cx
  Target Milestone: ---

Test case:

unsigned long a(void);
void b(long);
void c(void) {
    unsigned int x = a();
    b(-x);
}

There is a missed warning in the call to b().  x is negated, but as an int.  It
is then passed to b() which sees a very large positive number instead of a
small negative number.  This has recently affected the Linux codebase, and it's
disappointing that gcc doesn't have a warning that we could enable to find it.

https://godbolt.org/z/xvaxh1rqr

shows that Clang does spot this with -Wsign-conversion, but GCC currently
doesn't (it only warns for line 4 and not line 5).  Admittedly the Clang
diagnostic message isn't the greatest, but at least it says _something_.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-07-28 17:55 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-27 15:21 [Bug c/101645] New: -Wsign-conversion misses negation of unsigned int matthew at wil dot cx
2021-07-27 15:27 ` [Bug c/101645] " jrtc27 at jrtc27 dot com
2021-07-27 19:06 ` [Bug c/101645] warn about neg of unsigned type should be added to -Wsign-conversion pinskia at gcc dot gnu.org
2021-07-27 21:27 ` jhubbard at nvidia dot com
2021-07-28 12:35 ` matthew at wil dot cx
2021-07-28 17:55 ` redi at gcc dot gnu.org

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).