Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: John Baldwin <jhb@FreeBSD.org>
To: Simon Marchi <simon.marchi@polymtl.ca>
Cc: Simon Marchi <simon.marchi@ericsson.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH] Introduce in_inclusive_range, fix -Wtautological-compare warnings
Date: Mon, 30 Oct 2017 16:05:00 -0000	[thread overview]
Message-ID: <414aebc6-2dc6-d2b2-a1b4-35f98adb78f9@FreeBSD.org> (raw)
In-Reply-To: <d4eafbd4c4297f3f8f93d5388df4df2c@polymtl.ca>

On 10/30/17 4:01 PM, Simon Marchi wrote:
> On 2017-10-30 11:57, John Baldwin wrote:
>> On 10/30/17 2:32 PM, Simon Marchi wrote:
>>> When compiling with clang or gcc 8, we see warnings like this:
>>>
>>> /home/emaisin/src/binutils-gdb/gdb/arm-tdep.c:10013:13: error: 
>>> comparison of 0 <= unsigned expression is always true 
>>> [-Werror,-Wtautological-compare]
>>>       if (0 <= insn_op1 && 3 >= insn_op1)
>>>           ~ ^  ~~~~~~~~
>>> /home/emaisin/src/binutils-gdb/gdb/arm-tdep.c:11722:20: error: 
>>> comparison of unsigned expression >= 0 is always true 
>>> [-Werror,-Wtautological-compare]
>>>       else if (opB >= 0 && opB <= 2)
>>>                ~~~ ^  ~
>>>
>>> This is because an unsigned integer (opB in this case) will always be 
>>>> =
>>> 0.  It is still useful to keep both bounds of the range in the
>>> expression, even if one is at the edge of the data type range.  This
>>> patch introduces a utility function in_inclusive_range that gets rid 
>>> of
>>> the warning while conveying that we are checking for a range.
>>>
>>> Tested by rebuilding.
>>>
>>> gdb/ChangeLog:
>>>
>>> 	* common/common-utils.h (in_inclusive_range): New function.
>>> 	* arm-tdep.c (arm_record_extension_space): Use
>>> 	in_inclusive_range.
>>> 	* cris-tdep.c (cris_spec_reg_applicable): Use
>>> 	in_inclusive_range.
>>> ---
>>>  gdb/arm-tdep.c            | 4 ++--
>>>  gdb/common/common-utils.h | 9 +++++++++
>>>  gdb/cris-tdep.c           | 4 ++--
>>>  3 files changed, 13 insertions(+), 4 deletions(-)
>>>
>>> diff --git a/gdb/cris-tdep.c b/gdb/cris-tdep.c
>>> index d623eb6..209e29f 100644
>>> --- a/gdb/cris-tdep.c
>>> +++ b/gdb/cris-tdep.c
>>> @@ -1434,7 +1434,7 @@ cris_spec_reg_applicable (struct gdbarch 
>>> *gdbarch,
>>>        /* Indeterminate/obsolete.  */
>>>        return 0;
>>>      case cris_ver_v0_3:
>>> -      return (version >= 0 && version <= 3);
>>> +      return in_inclusive_range (version, 0U, 3U);
>>>      case cris_ver_v3p:
>>>        return (version >= 3);
>>>      case cris_ver_v8:
>>> @@ -1442,7 +1442,7 @@ cris_spec_reg_applicable (struct gdbarch 
>>> *gdbarch,
>>>      case cris_ver_v8p:
>>>        return (version >= 8);
>>>      case cris_ver_v0_10:
>>> -      return (version >= 0 && version <= 10);
>>> +      return in_inclusive_range (version, 0U, 10U);
>>>      case cris_ver_v3_10:
>>>        return (version >= 3 && version <= 10);
>>>      case cris_ver_v8_10:
>>
>> I wonder if in this file it wouldn't be best to use the new function 
>> throughout
>> the various cases so that the style is more consistent?  LGTM 
>> regardless.
> 
> 
> Good point, I'll make that change.  I'll see if it's possible in 
> arm-tdep.c too or if it's a too daunting task.

It may be sufficient to just be consistent within a function?  In arm-tdep.c
it is two instances in separate functions whereas for cris-tdep.c it is
multiple instances in the same function which is what stuck out to me.

-- 
John Baldwin


  reply	other threads:[~2017-10-30 16:05 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-28  3:24 Opinion about -Wtautological-compare Simon Marchi
2017-10-30  9:35 ` Yao Qi
2017-10-30 12:49   ` John Baldwin
2017-10-30 14:27     ` Simon Marchi
2017-10-30 14:33     ` [PATCH] Introduce in_inclusive_range, fix -Wtautological-compare warnings Simon Marchi
2017-10-30 15:57       ` John Baldwin
2017-10-30 16:01         ` Simon Marchi
2017-10-30 16:05           ` John Baldwin [this message]
2017-10-30 18:29             ` Simon Marchi

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=414aebc6-2dc6-d2b2-a1b4-35f98adb78f9@FreeBSD.org \
    --to=jhb@freebsd.org \
    --cc=gdb-patches@sourceware.org \
    --cc=simon.marchi@ericsson.com \
    --cc=simon.marchi@polymtl.ca \
    /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