From b020ff8074af22639e3f3c0f700f45d067521249 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Mon, 30 Oct 2017 14:27:30 -0400 Subject: 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. --- gdb/common/common-utils.h | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'gdb/common') 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 &v); joining all the arguments with a whitespace separating them. */ extern std::string stringify_argv (const std::vector &argv); +/* Return true if VALUE is in [LOW, HIGH]. */ + +template +static bool +in_inclusive_range (T value, T low, T high) +{ + return value >= low && value <= high; +} + #endif -- cgit v1.1