* [PATCH] gcc-plugins: Fix build with GCC 16.1
@ 2026-05-05 18:16 Jakub Jelinek
0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2026-05-05 18:16 UTC (permalink / raw)
To: linux-kernel
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
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-05-05 18:17 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-05 18:16 [PATCH] gcc-plugins: Fix build with GCC 16.1 Jakub Jelinek
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox