On 3/13/23 16:15, Jason Merrill wrote:
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.

...or I could build with a newer bootstrap compiler, I suppose.

        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

Reply via email to