* Opinion about -Wtautological-compare
@ 2017-10-28 3:24 Simon Marchi
2017-10-30 9:35 ` Yao Qi
0 siblings, 1 reply; 9+ messages in thread
From: Simon Marchi @ 2017-10-28 3:24 UTC (permalink / raw)
To: GDB Patches
Hi all,
When building with Clang, I see warnings like these in multiple files:
/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)
~~~ ^ ~
They are saying that because the variable is unsigned, the comparison
"variable >= 0" will always be true. What do you think we should do with
this?
1) Remove the comparisons and keep the warning:
- if (0 <= insn_op1 && 3 >= insn_op1)
+ if (3 >= insn_op1)
2) Leave the comparisons, but put them in comments and keep the warning:
- if (0 <= insn_op1 && 3 >= insn_op1)
+ if (/* 0 <= insn_op1 && */ 3 >= insn_op1)
3) Make a util function "in_inclusive_range" and use it (and keep the warning). Something like:
static bool
in_inclusive_range (unsigned int value, unsigned int low, unsigned int high)
{
return value >= low && value <= high;
}
and
- if (0 <= insn_op1 && 3 >= insn_op1)
+ if (in_inclusive_range (insn_op1, 0, 3))
4) Leave the code as-is and remove the warning (add -Wno-tautological-compare to the build).
Personally, I think the warning is useful and can reveal bugs, so I'd like to keep
it. I lean towards 2 or 3, because they help convey the idea that we check if the
value is within a range. If you are following with the architecture manual on the
side, it will probably show the same range (0-3) for those bits, so it helps if the
code does the same.
Simon
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: Opinion about -Wtautological-compare 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 0 siblings, 1 reply; 9+ messages in thread From: Yao Qi @ 2017-10-30 9:35 UTC (permalink / raw) To: Simon Marchi; +Cc: GDB Patches On Sat, Oct 28, 2017 at 4:24 AM, Simon Marchi <simon.marchi@ericsson.com> wrote: > Personally, I think the warning is useful and can reveal bugs, so I'd like to keep > it. I lean towards 2 or 3, because they help convey the idea that we check if the > value is within a range. If you are following with the architecture manual on the > side, it will probably show the same range (0-3) for those bits, so it helps if the > code does the same. > My vote is 3. PR 22188. -- Yao (齐尧) ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Opinion about -Wtautological-compare 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 0 siblings, 2 replies; 9+ messages in thread From: John Baldwin @ 2017-10-30 12:49 UTC (permalink / raw) To: Yao Qi, Simon Marchi; +Cc: GDB Patches On 10/30/17 9:35 AM, Yao Qi wrote: > On Sat, Oct 28, 2017 at 4:24 AM, Simon Marchi <simon.marchi@ericsson.com> wrote: > >> Personally, I think the warning is useful and can reveal bugs, so I'd like to keep >> it. I lean towards 2 or 3, because they help convey the idea that we check if the >> value is within a range. If you are following with the architecture manual on the >> side, it will probably show the same range (0-3) for those bits, so it helps if the >> code does the same. >> > > My vote is 3. PR 22188. I vote for 3 as well. I think it is useful to describe both bounds of a value explicitly even if one bound is at the "edge". -- John Baldwin ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Opinion about -Wtautological-compare 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 1 sibling, 0 replies; 9+ messages in thread From: Simon Marchi @ 2017-10-30 14:27 UTC (permalink / raw) To: John Baldwin; +Cc: Yao Qi, Simon Marchi, GDB Patches On 2017-10-30 08:49, John Baldwin wrote: > On 10/30/17 9:35 AM, Yao Qi wrote: >> On Sat, Oct 28, 2017 at 4:24 AM, Simon Marchi >> <simon.marchi@ericsson.com> wrote: >> >>> Personally, I think the warning is useful and can reveal bugs, so I'd >>> like to keep >>> it. I lean towards 2 or 3, because they help convey the idea that we >>> check if the >>> value is within a range. If you are following with the architecture >>> manual on the >>> side, it will probably show the same range (0-3) for those bits, so >>> it helps if the >>> code does the same. >>> >> >> My vote is 3. PR 22188. > > I vote for 3 as well. I think it is useful to describe both bounds of > a value > explicitly even if one bound is at the "edge". Thanks to you both, I'll post a patch shortly. Simon ^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH] Introduce in_inclusive_range, fix -Wtautological-compare warnings 2017-10-30 12:49 ` John Baldwin 2017-10-30 14:27 ` Simon Marchi @ 2017-10-30 14:33 ` Simon Marchi 2017-10-30 15:57 ` John Baldwin 1 sibling, 1 reply; 9+ messages in thread From: Simon Marchi @ 2017-10-30 14:33 UTC (permalink / raw) To: gdb-patches; +Cc: Simon Marchi 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/arm-tdep.c b/gdb/arm-tdep.c index def3958..282efe0 100644 --- a/gdb/arm-tdep.c +++ b/gdb/arm-tdep.c @@ -10010,7 +10010,7 @@ arm_record_extension_space (insn_decode_record *arm_insn_r) && !INSN_RECORDED(arm_insn_r)) { /* Handle MLA(S) and MUL(S). */ - if (0 <= insn_op1 && 3 >= insn_op1) + if (in_inclusive_range (insn_op1, 0U, 3U)) { record_buf[0] = bits (arm_insn_r->arm_insn, 12, 15); record_buf[1] = ARM_PS_REGNUM; @@ -11719,7 +11719,7 @@ thumb_record_ld_st_reg_offset (insn_decode_record *thumb_insn_r) record_buf[0] = reg_src1; thumb_insn_r->reg_rec_count = 1; } - else if (opB >= 0 && opB <= 2) + else if (in_inclusive_range (opB, 0U, 2U)) { /* STR(2), STRB(2), STRH(2) . */ reg_src1 = bits (thumb_insn_r->arm_insn, 3, 5); diff --git a/gdb/common/common-utils.h b/gdb/common/common-utils.h index a32863c..4926a32 100644 --- a/gdb/common/common-utils.h +++ b/gdb/common/common-utils.h @@ -125,4 +125,13 @@ extern void free_vector_argv (std::vector<char *> &v); joining all the arguments with a whitespace separating them. */ extern std::string stringify_argv (const std::vector<char *> &argv); +/* Return true if VALUE is in [LOW, HIGH]. */ + +template <typename T> +static bool +in_inclusive_range (T value, T low, T high) +{ + return value >= low && value <= high; +} + #endif 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: -- 2.7.4 ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] Introduce in_inclusive_range, fix -Wtautological-compare warnings 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 0 siblings, 1 reply; 9+ messages in thread From: John Baldwin @ 2017-10-30 15:57 UTC (permalink / raw) To: Simon Marchi, gdb-patches 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. -- John Baldwin ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] Introduce in_inclusive_range, fix -Wtautological-compare warnings 2017-10-30 15:57 ` John Baldwin @ 2017-10-30 16:01 ` Simon Marchi 2017-10-30 16:05 ` John Baldwin 0 siblings, 1 reply; 9+ messages in thread From: Simon Marchi @ 2017-10-30 16:01 UTC (permalink / raw) To: John Baldwin; +Cc: Simon Marchi, gdb-patches 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. Simon ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] Introduce in_inclusive_range, fix -Wtautological-compare warnings 2017-10-30 16:01 ` Simon Marchi @ 2017-10-30 16:05 ` John Baldwin 2017-10-30 18:29 ` Simon Marchi 0 siblings, 1 reply; 9+ messages in thread From: John Baldwin @ 2017-10-30 16:05 UTC (permalink / raw) To: Simon Marchi; +Cc: Simon Marchi, gdb-patches 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 ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] Introduce in_inclusive_range, fix -Wtautological-compare warnings 2017-10-30 16:05 ` John Baldwin @ 2017-10-30 18:29 ` Simon Marchi 0 siblings, 0 replies; 9+ messages in thread From: Simon Marchi @ 2017-10-30 18:29 UTC (permalink / raw) To: John Baldwin, Simon Marchi; +Cc: gdb-patches On 2017-10-30 12:05 PM, John Baldwin wrote: > 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. In arm-tdep.c, I ended changing the other instances in the functions that were already touched by the patch, for consistency. This is what I pushed: commit b020ff8074af22639e3f3c0f700f45d067521249 Author: Simon Marchi <simon.marchi@ericsson.com> Date: Mon Oct 30 14:27:30 2017 -0400 Introduce in_inclusive_range, fix -Wtautological-compare warnings 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. (thumb_record_ld_st_reg_offset): Use in_inclusive_range. * cris-tdep.c (cris_spec_reg_applicable): Use in_inclusive_range. diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 2855f4d..5a680ed 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,12 @@ +2017-10-30 Simon Marchi <simon.marchi@ericsson.com> + + * common/common-utils.h (in_inclusive_range): New function. + * arm-tdep.c (arm_record_extension_space): Use + in_inclusive_range. + (thumb_record_ld_st_reg_offset): Use in_inclusive_range. + * cris-tdep.c (cris_spec_reg_applicable): Use + in_inclusive_range. + 2017-10-30 Pedro Alves <palves@redhat.com> Simon Marchi <simon.marchi@ericsson.com> diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c index def3958..46b7888 100644 --- a/gdb/arm-tdep.c +++ b/gdb/arm-tdep.c @@ -10010,13 +10010,13 @@ arm_record_extension_space (insn_decode_record *arm_insn_r) && !INSN_RECORDED(arm_insn_r)) { /* Handle MLA(S) and MUL(S). */ - if (0 <= insn_op1 && 3 >= insn_op1) + if (in_inclusive_range (insn_op1, 0U, 3U)) { record_buf[0] = bits (arm_insn_r->arm_insn, 12, 15); record_buf[1] = ARM_PS_REGNUM; arm_insn_r->reg_rec_count = 2; } - else if (4 <= insn_op1 && 15 >= insn_op1) + else if (in_inclusive_range (insn_op1, 4U, 15U)) { /* Handle SMLAL(S), SMULL(S), UMLAL(S), UMULL(S). */ record_buf[0] = bits (arm_insn_r->arm_insn, 16, 19); @@ -11712,14 +11712,14 @@ thumb_record_ld_st_reg_offset (insn_decode_record *thumb_insn_r) /* Handle load/store register offset. */ uint32_t opB = bits (thumb_insn_r->arm_insn, 9, 11); - if (opB >= 4 && opB <= 7) + if (in_inclusive_range (opB, 4U, 7U)) { /* LDR(2), LDRB(2) , LDRH(2), LDRSB, LDRSH. */ reg_src1 = bits (thumb_insn_r->arm_insn,0, 2); record_buf[0] = reg_src1; thumb_insn_r->reg_rec_count = 1; } - else if (opB >= 0 && opB <= 2) + else if (in_inclusive_range (opB, 0U, 2U)) { /* STR(2), STRB(2), STRH(2) . */ reg_src1 = bits (thumb_insn_r->arm_insn, 3, 5); diff --git a/gdb/common/common-utils.h b/gdb/common/common-utils.h index a32863c..4926a32 100644 --- a/gdb/common/common-utils.h +++ b/gdb/common/common-utils.h @@ -125,4 +125,13 @@ extern void free_vector_argv (std::vector<char *> &v); joining all the arguments with a whitespace separating them. */ extern std::string stringify_argv (const std::vector<char *> &argv); +/* Return true if VALUE is in [LOW, HIGH]. */ + +template <typename T> +static bool +in_inclusive_range (T value, T low, T high) +{ + return value >= low && value <= high; +} + #endif diff --git a/gdb/cris-tdep.c b/gdb/cris-tdep.c index d623eb6..416843f 100644 --- a/gdb/cris-tdep.c +++ b/gdb/cris-tdep.c @@ -1434,19 +1434,19 @@ 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: - return (version == 8 || version == 9); + return in_inclusive_range (version, 8U, 9U); 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); + return in_inclusive_range (version, 3U, 10U); case cris_ver_v8_10: - return (version >= 8 && version <= 10); + return in_inclusive_range (version, 8U, 10U); case cris_ver_v10: return (version == 10); case cris_ver_v10p: ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2017-10-30 18:29 UTC | newest] Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 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 2017-10-30 18:29 ` Simon Marchi
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox