public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH RFA] tree: define tree_code_type in C++11/14 [PR108634]
@ 2023-03-13 20:15 Jason Merrill
  2023-03-13 20:47 ` Jason Merrill
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Jason Merrill @ 2023-03-13 20:15 UTC (permalink / raw)
  To: gcc-patches; +Cc: Jakub Jelinek

Tested x86_64-pc-linux-gnu, OK for trunk?

-- 8< --

The r13-6577 change to use tree_code_type_tmpl in earlier C++ dialects broke
gdbhooks, which expects tree_code_type to always be available.  I considered
trying to make gdbhooks more robust, but it seemed simpler to define
tree_code_type as a reference to the template.  This still ends up with a
definition of the reference in each translation unit, but that's allowed by the
ODR because it always refers to the same entity, and is much smaller than
having the whole table in each TU.

	PR plugins/108634

gcc/ChangeLog:

	* tree-core.h (tree_code_type, tree_code_length):
	Define even without inline variable support.
	* tree.h (TREE_CODE_CLASS, TREE_CODE_LENGTH):
	Only one definition.
---
 gcc/tree-core.h |  3 +++
 gcc/tree.h      | 10 ----------
 2 files changed, 3 insertions(+), 10 deletions(-)

diff --git a/gcc/tree-core.h b/gcc/tree-core.h
index fd2be57b78c..545dfd30114 100644
--- a/gcc/tree-core.h
+++ b/gcc/tree-core.h
@@ -2298,6 +2298,7 @@ struct tree_code_type_tmpl {
 
 template <int N>
 constexpr enum tree_code_class tree_code_type_tmpl<N>::tree_code_type[];
+static constexpr auto &tree_code_type = tree_code_type_tmpl<0>::tree_code_type;
 #else
 constexpr inline enum tree_code_class tree_code_type[] = {
 #include "all-tree.def"
@@ -2326,6 +2327,8 @@ struct tree_code_length_tmpl {
 
 template <int N>
 constexpr unsigned char tree_code_length_tmpl<N>::tree_code_length[];
+static constexpr auto &tree_code_length
+= tree_code_length_tmpl<0>::tree_code_length;
 #else
 constexpr inline unsigned char tree_code_length[] = {
 #include "all-tree.def"
diff --git a/gcc/tree.h b/gcc/tree.h
index 91375f9652f..92ac0e6a214 100644
--- a/gcc/tree.h
+++ b/gcc/tree.h
@@ -177,12 +177,7 @@ code_helper::is_builtin_fn () const
 #define TREE_CODE_CLASS_STRING(CLASS)\
         tree_code_class_strings[(int) (CLASS)]
 
-#if __cpp_inline_variables < 201606L
-#define TREE_CODE_CLASS(CODE)	\
-  tree_code_type_tmpl <0>::tree_code_type[(int) (CODE)]
-#else
 #define TREE_CODE_CLASS(CODE)	tree_code_type[(int) (CODE)]
-#endif
 
 /* Nonzero if NODE represents an exceptional code.  */
 
@@ -276,12 +271,7 @@ code_helper::is_builtin_fn () const
 
 #define EXPR_P(NODE) IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (NODE)))
 
-#if __cpp_inline_variables < 201606L
-#define TREE_CODE_LENGTH(CODE)	\
-  tree_code_length_tmpl <0>::tree_code_length[(int) (CODE)]
-#else
 #define TREE_CODE_LENGTH(CODE)	tree_code_length[(int) (CODE)]
-#endif
 
 
 /* Helper macros for math builtins.  */

base-commit: c227508d06a63f9b8fede3fd88813accb447060e
-- 
2.31.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-03-14 15:54 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-13 20:15 [PATCH RFA] tree: define tree_code_type in C++11/14 [PR108634] Jason Merrill
2023-03-13 20:47 ` Jason Merrill
2023-03-13 21:02 ` Jakub Jelinek
2023-03-13 21:54   ` Jakub Jelinek
2023-03-14 15:42 ` [PATCH] gdbhooks: Update gdbhooks.py for recent tree_code_type changes [PR108634] Jakub Jelinek
2023-03-14 15:54   ` Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).