aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@ericsson.com>2017-10-30 14:27:30 -0400
committerSimon Marchi <simon.marchi@ericsson.com>2017-10-30 14:27:38 -0400
commitb020ff8074af22639e3f3c0f700f45d067521249 (patch)
tree52a5dcc3bd2b298e814b8f43c74d6aeac22edced
parent1b81856f5b00e7ba860e4de2f3a426f342327165 (diff)
downloadgdb-b020ff8074af22639e3f3c0f700f45d067521249.zip
gdb-b020ff8074af22639e3f3c0f700f45d067521249.tar.gz
gdb-b020ff8074af22639e3f3c0f700f45d067521249.tar.bz2
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.
-rw-r--r--gdb/ChangeLog9
-rw-r--r--gdb/arm-tdep.c8
-rw-r--r--gdb/common/common-utils.h9
-rw-r--r--gdb/cris-tdep.c10
4 files changed, 27 insertions, 9 deletions
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: