From: "Satyam Sharma" <satyam.sharma@gmail.com>
To: "Roland Dreier" <rdreier@cisco.com>
Cc: openib-general@openib.org, linux-kernel@vger.kernel.org
Subject: Re: dealing with gcc 'comparison is always false' warnings (was: [PATCH] drivers/infiniband: fix comparsion between unsigned and negative)
Date: Wed, 30 May 2007 21:11:29 +0530 [thread overview]
Message-ID: <a781481a0705300841k2a02335eg66985129eaed28f4@mail.gmail.com> (raw)
In-Reply-To: <adazm3mqqh3.fsf@cisco.com>
On 5/30/07, Roland Dreier <rdreier@cisco.com> wrote:
> thanks... I'm wondering if there's a consensus among kernel hackers
> about changes like:
>
> > - if (hdr.cmd < 0 || hdr.cmd >= ARRAY_SIZE(ucma_cmd_table))
> > + if (hdr.cmd >= ARRAY_SIZE(ucma_cmd_table))
> > return -EINVAL;
>
> I understand that new gcc sees that hdr.cmd is unsigned and hence
> can't be < 0, and generates a warning for that, and having a build
> cluttered with warnings hides bugs and so on. However the code here
> looks quite sensible to me -- otherwise we end up with missing range
> checking if hdr.cmd ever changes to a signed type. This seems like a
> good way to introduce bugs: delete valid range checking code to shut
> up a silly gcc warning, and then change the type of a variable.
You're *absolutely* correct about the issue that these "fixes" that remove
such conditions end up remove range-checking making the code more
flakey / less readable.
However, gcc is _just as correct_. It is only crying about seeing a condition
that the programmer could have written with some purpose in mind but which
is being completely compiled away by it when generating the code because
of it being a tautology / contradiction ...
> Can't we just make gcc shut up about the comparison and generate no
> code for it because it knows it can't be true?
No, shutting gcc up wouldn't be the right thing, IMHO. These warnings are
a good reminder to the programmer to go and see if there is a real bug
somewhere and if something really needs to be done with the code (could
be simply to change the type of a variable to signed that was mistakenly
declared unsigned, f.e.).
But yes, the kind of "fixes" you pointed out that _remove_ these conditions
are definitely *not* what we would want to do.
Satyam
next prev parent reply other threads:[~2007-05-30 15:43 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-05-30 8:05 [PATCH] drivers/infiniband: fix comparsion between unsigned and negative Bill Nottingham
2007-05-30 15:30 ` dealing with gcc 'comparison is always false' warnings (was: [PATCH] drivers/infiniband: fix comparsion between unsigned and negative) Roland Dreier
2007-05-30 15:41 ` Satyam Sharma [this message]
2007-05-30 15:56 ` [ofa-general] Re: dealing with gcc 'comparison is always false' warnings Roland Dreier
2007-05-30 17:00 ` Satyam Sharma
2007-05-30 16:06 ` dealing with gcc 'comparison is always false' warnings (was: [PATCH] drivers/infiniband: fix comparsion between unsigned and negative) Satyam Sharma
2007-05-30 19:00 ` dealing with gcc 'comparison is always false' warnings Tilman Schmidt
2007-05-30 19:14 ` Satyam Sharma
2007-05-30 19:09 ` dealing with gcc 'comparison is always false' warnings (was: [PATCH] drivers/infiniband: fix comparsion between unsigned and negative) Bill Nottingham
2007-05-30 19:23 ` Satyam Sharma
2007-05-30 20:48 ` [ofa-general] [PATCH] drivers/infiniband: fix comparsion between unsigned and negative Roland Dreier
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=a781481a0705300841k2a02335eg66985129eaed28f4@mail.gmail.com \
--to=satyam.sharma@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=openib-general@openib.org \
--cc=rdreier@cisco.com \
/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
all inboxes | Powered by JetHome®