Gentoo Archives: gentoo-commits

From: Sam James <sam@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] repo/gentoo:master commit in: sys-devel/gdb/files/, sys-devel/gdb/
Date: Sun, 19 Mar 2023 21:52:23
Message-Id: 1679262719.572e86ac9b0838f4e227460fb482166bce46f961.sam@gentoo
1 commit: 572e86ac9b0838f4e227460fb482166bce46f961
2 Author: Sam James <sam <AT> gentoo <DOT> org>
3 AuthorDate: Sun Mar 19 21:51:59 2023 +0000
4 Commit: Sam James <sam <AT> gentoo <DOT> org>
5 CommitDate: Sun Mar 19 21:51:59 2023 +0000
6 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=572e86ac
7
8 sys-devel/gdb: fix build w/ clang 16 (-Wenum-constexpr-conversion)
9
10 Closes: https://bugs.gentoo.org/894174
11 Signed-off-by: Sam James <sam <AT> gentoo.org>
12
13 ...b-13.1-Wenum-constexpr-conversion-clang16.patch | 128 +++++++++++++++++++++
14 sys-devel/gdb/gdb-13.1-r1.ebuild | 1 +
15 2 files changed, 129 insertions(+)
16
17 diff --git a/sys-devel/gdb/files/gdb-13.1-Wenum-constexpr-conversion-clang16.patch b/sys-devel/gdb/files/gdb-13.1-Wenum-constexpr-conversion-clang16.patch
18 new file mode 100644
19 index 000000000000..adc09f83ea68
20 --- /dev/null
21 +++ b/sys-devel/gdb/files/gdb-13.1-Wenum-constexpr-conversion-clang16.patch
22 @@ -0,0 +1,128 @@
23 +https://bugs.gentoo.org/894174
24 +https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=ae61525fcf456ab395d55c45492a106d1275873a
25 +
26 +From ae61525fcf456ab395d55c45492a106d1275873a Mon Sep 17 00:00:00 2001
27 +From: Simon Marchi <simon.marchi@××××××××.com>
28 +Date: Thu, 23 Feb 2023 12:35:40 -0500
29 +Subject: [PATCH] gdbsupport: ignore -Wenum-constexpr-conversion in
30 + enum-flags.h
31 +
32 +When building with clang 16, we get:
33 +
34 + CXX gdb.o
35 + In file included from /home/smarchi/src/binutils-gdb/gdb/gdb.c:19:
36 + In file included from /home/smarchi/src/binutils-gdb/gdb/defs.h:65:
37 + /home/smarchi/src/binutils-gdb/gdb/../gdbsupport/enum-flags.h:95:52: error: integer value -1 is outside the valid range of values [0, 15] for this enumeration type [-Wenum-constexpr-conversion]
38 + integer_for_size<sizeof (T), static_cast<bool>(T (-1) < T (0))>::type
39 + ^
40 +
41 +The error message does not make it clear in the context of which enum
42 +flag this fails (i.e. what is T in this context), but it doesn't really
43 +matter, we have similar warning/errors for many of them, if we let the
44 +build go through.
45 +
46 +clang is right that the value -1 is invalid for the enum type we cast -1
47 +to. However, we do need this expression in order to select an integer
48 +type with the appropriate signedness. That is, with the same signedness
49 +as the underlying type of the enum.
50 +
51 +I first wondered if that was really needed, if we couldn't use
52 +std::underlying_type for that. It turns out that the comment just above
53 +says:
54 +
55 + /* Note that std::underlying_type<enum_type> is not what we want here,
56 + since that returns unsigned int even when the enum decays to signed
57 + int. */
58 +
59 +I was surprised, because std::is_signed<std::underlying_type<enum_type>>
60 +returns the right thing. So I tried replacing all this with
61 +std::underlying_type, see if that would work. Doing so causes some
62 +build failures in unittests/enum-flags-selftests.c:
63 +
64 + CXX unittests/enum-flags-selftests.o
65 + /home/smarchi/src/binutils-gdb/gdb/unittests/enum-flags-selftests.c:254:1: error: static assertion failed due to requirement 'gdb::is_same<selftests::enum_flags_tests::check_valid_expr254::archetype<enum_flags<s
66 + elftests::enum_flags_tests::RE>, selftests::enum_flags_tests::RE, enum_flags<selftests::enum_flags_tests::RE2>, selftests::enum_flags_tests::RE2, enum_flags<selftests::enum_flags_tests::URE>, selftests::enum_fla
67 + gs_tests::URE, int>, selftests::enum_flags_tests::check_valid_expr254::archetype<enum_flags<selftests::enum_flags_tests::RE>, selftests::enum_flags_tests::RE, enum_flags<selftests::enum_flags_tests::RE2>, selfte
68 + sts::enum_flags_tests::RE2, enum_flags<selftests::enum_flags_tests::URE>, selftests::enum_flags_tests::URE, unsigned int>>::value == true':
69 + CHECK_VALID (true, int, true ? EF () : EF2 ())
70 + ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
71 + /home/smarchi/src/binutils-gdb/gdb/unittests/enum-flags-selftests.c:91:3: note: expanded from macro 'CHECK_VALID'
72 + CHECK_VALID_EXPR_6 (EF, RE, EF2, RE2, UEF, URE, VALID, EXPR_TYPE, EXPR)
73 + ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
74 + /home/smarchi/src/binutils-gdb/gdb/../gdbsupport/valid-expr.h:105:3: note: expanded from macro 'CHECK_VALID_EXPR_6'
75 + CHECK_VALID_EXPR_INT (ESC_PARENS (typename T1, typename T2, \
76 + ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
77 + /home/smarchi/src/binutils-gdb/gdb/../gdbsupport/valid-expr.h:66:3: note: expanded from macro 'CHECK_VALID_EXPR_INT'
78 + static_assert (gdb::is_detected_exact<archetype<TYPES, EXPR_TYPE>, \
79 + ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
80 +
81 +This is a bit hard to decode, but basically enumerations have the
82 +following funny property that they decay into a signed int, even if
83 +their implicit underlying type is unsigned. This code:
84 +
85 + enum A {};
86 + enum B {};
87 +
88 + int main() {
89 + std::cout << std::is_signed<std::underlying_type<A>::type>::value
90 + << std::endl;
91 + std::cout << std::is_signed<std::underlying_type<B>::type>::value
92 + << std::endl;
93 + auto result = true ? A() : B();
94 + std::cout << std::is_signed<decltype(result)>::value << std::endl;
95 + }
96 +
97 +produces:
98 +
99 + 0
100 + 0
101 + 1
102 +
103 +So, the "CHECK_VALID" above checks that this property works for enum flags the
104 +same way as it would if you were using their underlying enum types. And
105 +somehow, changing integer_for_size to use std::underlying_type breaks that.
106 +
107 +Since the current code does what we want, and I don't see any way of doing it
108 +differently, ignore -Wenum-constexpr-conversion around it.
109 +
110 +Change-Id: Ibc82ae7bbdb812102ae3f1dd099fc859dc6f3cc2
111 +--- a/gdbsupport/enum-flags.h
112 ++++ b/gdbsupport/enum-flags.h
113 +@@ -91,9 +91,12 @@ template<> struct integer_for_size<8, 1> { typedef int64_t type; };
114 + template<typename T>
115 + struct enum_underlying_type
116 + {
117 ++ DIAGNOSTIC_PUSH
118 ++ DIAGNOSTIC_IGNORE_ENUM_CONSTEXPR_CONVERSION
119 + typedef typename
120 + integer_for_size<sizeof (T), static_cast<bool>(T (-1) < T (0))>::type
121 + type;
122 ++ DIAGNOSTIC_POP
123 + };
124 +
125 + namespace enum_flags_detail
126 +--- a/include/diagnostics.h
127 ++++ b/include/diagnostics.h
128 +@@ -76,6 +76,11 @@
129 + # define DIAGNOSTIC_ERROR_SWITCH \
130 + DIAGNOSTIC_ERROR ("-Wswitch")
131 +
132 ++# if __has_warning ("-Wenum-constexpr-conversion")
133 ++# define DIAGNOSTIC_IGNORE_ENUM_CONSTEXPR_CONVERSION \
134 ++ DIAGNOSTIC_IGNORE ("-Wenum-constexpr-conversion")
135 ++# endif
136 ++
137 + #elif defined (__GNUC__) /* GCC */
138 +
139 + # define DIAGNOSTIC_IGNORE_DEPRECATED_DECLARATIONS \
140 +@@ -155,4 +160,8 @@
141 + # define DIAGNOSTIC_ERROR_SWITCH
142 + #endif
143 +
144 ++#ifndef DIAGNOSTIC_IGNORE_ENUM_CONSTEXPR_CONVERSION
145 ++# define DIAGNOSTIC_IGNORE_ENUM_CONSTEXPR_CONVERSION
146 ++#endif
147 ++
148 + #endif /* DIAGNOSTICS_H */
149 +--
150 +2.31.1
151
152 diff --git a/sys-devel/gdb/gdb-13.1-r1.ebuild b/sys-devel/gdb/gdb-13.1-r1.ebuild
153 index bc86849c6276..60adac18680f 100644
154 --- a/sys-devel/gdb/gdb-13.1-r1.ebuild
155 +++ b/sys-devel/gdb/gdb-13.1-r1.ebuild
156 @@ -101,6 +101,7 @@ BDEPEND="
157
158 PATCHES=(
159 "${FILESDIR}"/${PN}-8.3.1-verbose-build.patch
160 + "${FILESDIR}"/${P}-Wenum-constexpr-conversion-clang16.patch
161 )
162
163 pkg_setup() {