public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "segher at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug other/102440] Uinteger Opt/Param but the underlying type is signed Date: Tue, 26 Oct 2021 16:45:57 +0000 [thread overview] Message-ID: <bug-102440-4-cZZEy0Ygk1@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-102440-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102440 --- Comment #9 from Segher Boessenkool <segher at gcc dot gnu.org> --- (In reply to Martin Liška from comment #8) > > We could make the "UInteger" type mean it is implemented with an "unsigned > > int" > > C type (or some other unsigned integer type). > > This would lead to the following list of -Wsign-compare warnings: > > /home/marxin/Programming/gcc/gcc/c-family/c-opts.c:934:27: warning: > comparison of integer expressions of different signedness: ‘unsigned int’ > and ‘int’ [-Wsign-compare] That line is if (warn_shift_overflow == -1) The documentation for that warning flag says '-Wsign-compare' Warn when a comparison between signed and unsigned values could produce an incorrect result when the signed value is converted to unsigned. In C++, this warning is also enabled by '-Wall'. In C, it is also enabled by '-Wextra'. I don't see how this could produce an incorrect result. Writing the code as if (warn_shift_overflow == -1U) means exactly the same thing, except it assumes the size of the variable so it is a bad habit. Plain "-1" is easier to read anyway. It is idiom to use -1 for all-bits-set for unsigned vars. It works correctly whatever the size of the variable is. It is silly if if (warn_shift_overflow == -1) warns, but if (warn_shift_overflow + 1 == 0) is just dandy (and that is the current situation :-( ) > One would need to verify/adjust all these places (plus many more for other > targets). Or fix the bloody warning ;-) But not something you want on your plate, I fully understand :-)
prev parent reply other threads:[~2021-10-26 16:45 UTC|newest] Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-09-22 3:11 [Bug tree-optimization/102440] New: " linkw at gcc dot gnu.org 2021-09-22 3:13 ` [Bug middle-end/102440] " linkw at gcc dot gnu.org 2021-09-22 5:47 ` [Bug other/102440] " pinskia at gcc dot gnu.org 2021-09-23 6:23 ` linkw at gcc dot gnu.org 2021-09-27 13:29 ` marxin at gcc dot gnu.org 2021-10-25 15:00 ` marxin at gcc dot gnu.org 2021-10-25 20:53 ` segher at gcc dot gnu.org 2021-10-25 21:14 ` segher at gcc dot gnu.org 2021-10-26 15:17 ` marxin at gcc dot gnu.org 2021-10-26 16:45 ` segher at gcc dot gnu.org [this message]
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-102440-4-cZZEy0Ygk1@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: linkBe 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).