On 8/13/25 6:29 AM, Jakub Jelinek wrote:
Hi!
My r16-3059 PR120778 change which introduced the -Wkeyword-macro option
and made it a default for C++26 -pedantic broke quite a few tests on
powerpc*. The problem is that the backend predefines bool and _Bool as
macros (unclear why _Bool for C++ because in C++ _Bool is not a keyword)
to make it a NODE_CONDITIONAL macro, so for e.g. -std=c++26 -pedantic-errors
we diagnose it on every TU as an error.
C++26 says that
#define bool anything
or
#undef bool
is invalid, diagnostic required (but in order not to break too much stuff
in the wild, we do it only if -pedantic or when user asks for it with
-Wkeyword-macro). When the backend predefines it, there is no way user
can avoid that diagnostics and the backend ensures it will DTRT.
Fixed by temporarily disabling the NODE_WARN flag on those, so that the
warnings or errors aren't reported when the backend predefines the macro.
#undef bool
later on by users or redefines to something else will be still diagnosed.
Could we suppress warnings for all builtin_define instead of
specifically for these names?
Bootstrapped/regtested on powerpc64le-linux, ok for trunk?
2025-08-13 Jakub Jelinek <ja...@redhat.com>
PR target/121520
* config/rs6000/rs6000-c.cc (rs6000_cpu_cpp_builtins): Temporarily
clear NODE_WARN flag on "bool" or "_Bool" around builtin_define
of those keywords if warn_keyword_macro.
--- gcc/config/rs6000/rs6000-c.cc.jj 2025-04-08 14:08:49.819301801 +0200
+++ gcc/config/rs6000/rs6000-c.cc 2025-08-13 09:00:07.115878529 +0200
@@ -636,8 +636,30 @@ rs6000_cpu_cpp_builtins (cpp_reader *pfi
{
builtin_define ("vector=vector");
builtin_define ("pixel=pixel");
- builtin_define ("bool=bool");
- builtin_define ("_Bool=_Bool");
+ if (warn_keyword_macro)
+ {
+ cpp_lookup (parse_in,
+ (const unsigned char *) "bool",
+ sizeof ("bool") - 1)->flags &= ~NODE_WARN;
+ builtin_define ("bool=bool");
+ cpp_lookup (parse_in,
+ (const unsigned char *) "bool",
+ sizeof ("bool") - 1)->flags |= NODE_WARN;
+ }
+ else
+ builtin_define ("bool=bool");
+ if (warn_keyword_macro && !c_dialect_cxx ())
+ {
+ cpp_lookup (parse_in,
+ (const unsigned char *) "_Bool",
+ sizeof ("_Bool") - 1)->flags &= ~NODE_WARN;
+ builtin_define ("_Bool=_Bool");
+ cpp_lookup (parse_in,
+ (const unsigned char *) "_Bool",
+ sizeof ("_Bool") - 1)->flags |= NODE_WARN;
+ }
+ else
+ builtin_define ("_Bool=_Bool");
init_vector_keywords ();
/* Enable context-sensitive macros. */
Jakub