From: Jakub Jelinek <jakub@redhat.com>
To: linux-kernel@vger.kernel.org
Subject: [PATCH] gcc-plugins: Fix build with GCC 16.1
Date: Tue, 5 May 2026 20:16:54 +0200 [thread overview]
Message-ID: <afo0FvJiNAotYinD@tucnak> (raw)
GCC is written in C++ for 13 years already, and from the time it
was implemented in C and times when it could be built by both C and C++
there were various CONST_CAST* macros. In GCC 16 these macros were
removed because one can use C++ const_cast directly.
The kernel gcc-plugins use 2 of those macros though, so when GCC plugins
are enabled, kernel fails to build with
In file included from scripts/gcc-plugins/latent_entropy_plugin.c:78:
scripts/gcc-plugins/gcc-common.h: In function ‘void debug_tree(const_tree)’:
scripts/gcc-plugins/gcc-common.h:417:20: error: ‘CONST_CAST_TREE’ was not declared in this scope; did you mean ‘CONST_CAST_EXPR’?
417 | debug_tree(CONST_CAST_TREE(t));
| ^~~~~~~~~~~~~~~
| CONST_CAST_EXPR
scripts/gcc-plugins/gcc-common.h: In function ‘void debug_gimple_stmt(const_gimple_ptr)’:
scripts/gcc-plugins/gcc-common.h:312:47: error: expected primary-expression before ‘,’ token
312 | #define CONST_CAST_GIMPLE(X) CONST_CAST(gimple, (X))
| ^
scripts/gcc-plugins/gcc-common.h:422:27: note: in expansion of macro ‘CONST_CAST_GIMPLE’
422 | debug_gimple_stmt(CONST_CAST_GIMPLE(s));
| ^~~~~~~~~~~~~~~~~
scripts/gcc-plugins/gcc-common.h:312:30: error: ‘CONST_CAST’ was not declared in this scope; did you mean ‘CONST_INT’?
312 | #define CONST_CAST_GIMPLE(X) CONST_CAST(gimple, (X))
| ^~~~~~~~~~
scripts/gcc-plugins/gcc-common.h:422:27: note: in expansion of macro ‘CONST_CAST_GIMPLE’
422 | debug_gimple_stmt(CONST_CAST_GIMPLE(s));
| ^~~~~~~~~~~~~~~~~
The following patch fixes it by defining the macros the way
they were defined in GCC 15 and earlier for the plugin compatibility
layer.
Tested with both GCC 15.2.1 (where it works before/after this patch) and
GCC 16.1.1 (where it is fixed with it).
Signed-off-by: Jakub Jelinek <jakub@redhat.com>
diff --git a/scripts/gcc-plugins/gcc-common.h b/scripts/gcc-plugins/gcc-common.h
index 8f1b3500f8e2..0e46215793ba 100644
--- a/scripts/gcc-plugins/gcc-common.h
+++ b/scripts/gcc-plugins/gcc-common.h
@@ -304,6 +304,12 @@ static inline void cgraph_call_edge_duplication_hooks(cgraph_edge *cs1, cgraph_e
symtab->call_edge_duplication_hooks(cs1, cs2);
}
+
+#if BUILDING_GCC_VERSION >= 16000
+#define CONST_CAST(TYPE, X) (const_cast<TYPE>(X))
+#define CONST_CAST_TREE(X) CONST_CAST(union tree_node *, (X))
+#endif
+
typedef gimple *gimple_ptr;
typedef const gimple *const_gimple_ptr;
#define gimple gimple_ptr
reply other threads:[~2026-05-05 18:17 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=afo0FvJiNAotYinD@tucnak \
--to=jakub@redhat.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox