Skip to content

Commit

Permalink
gdb: fix clang integer value -1 outside valid range error
Browse files Browse the repository at this point in the history
Backport gdb patch to fix the "integer value -1 is outside the valid range of values" errors when building with clang 16+.

Without the patch, when using clang 16 to build, we get some errors like:
    In file included from cp-valprint.c:20:
    In file included from ./defs.h:65:
    ./../gdbsupport/enum-flags.h:85:52: error: integer value -1 is outside the valid range of values [0, 15] for the enumeration type 'ui_out_flag' [-Wenum-constexpr-conversion]
       85 |     integer_for_size<sizeof (T), static_cast<bool>(T (-1) < T (0))>::type
          |                                                    ^                                           ^

GDB ignore -Wenum-constexpr-conversion around enum-flags.h to solve the problem.

Related GDB commit:
8cbde735e405 "gdbsupport: ignore -Wenum-constexpr-conversion in enum-flags.h"
  • Loading branch information
yanyir committed Aug 31, 2024
1 parent 79b93ec commit 9cc62d3
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions gdb-10.2.patch
Original file line number Diff line number Diff line change
Expand Up @@ -16118,3 +16118,46 @@ exit 0
subclass (SYMBOL_NONE)
{
/* We can't use an initializer list for members of a base class, and
--- gdb-10.2/gdbsupport/enum-flags.h.orig
+++ gdb-10.2/gdbsupport/enum-flags.h
@@ -81,9 +81,12 @@
template<typename T>
struct enum_underlying_type
{
+ DIAGNOSTIC_PUSH
+ DIAGNOSTIC_IGNORE_ENUM_CONSTEXPR_CONVERSION
typedef typename
integer_for_size<sizeof (T), static_cast<bool>(T (-1) < T (0))>::type
type;
+ DIAGNOSTIC_POP
};

template <typename E>

--- gdb-10.2/include/diagnostics.h.orig
+++ gdb-10.2/include/diagnostics.h
@@ -61,6 +61,24 @@
# define DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL \
DIAGNOSTIC_IGNORE ("-Wformat-nonliteral")

+# if __has_warning ("-Wuser-defined-warnings")
+# define DIAGNOSTIC_IGNORE_USER_DEFINED_WARNINGS \
+ DIAGNOSTIC_IGNORE ("-Wuser-defined-warnings")
+# endif
+
+# if __has_warning ("-Wunused-but-set-variable")
+# define DIAGNOSTIC_IGNORE_UNUSED_BUT_SET_VARIABLE \
+ DIAGNOSTIC_IGNORE ("-Wunused-but-set-variable")
+# endif
+
+# define DIAGNOSTIC_ERROR_SWITCH \
+ DIAGNOSTIC_ERROR ("-Wswitch")
+
+# if __has_warning ("-Wenum-constexpr-conversion")
+# define DIAGNOSTIC_IGNORE_ENUM_CONSTEXPR_CONVERSION \
+ DIAGNOSTIC_IGNORE ("-Wenum-constexpr-conversion")
+# endif
+
#elif defined (__GNUC__) /* GCC */

# if __GNUC__ >= 7

0 comments on commit 9cc62d3

Please sign in to comment.