On Thu, Dec 11, 2025 at 07:55:38PM +0700, Jason Merrill wrote:
> > Resolved in
> > <https://forge.sourceware.org/marek/gcc/commit/06e3ccc259570c2e2c7ab4e997d38326e8afc53d>
>
> I'd still prefer END_OF_BASE_TREE_CODES rather than the (equal)
> LAST_AND_UNUSED_TREE_CODE.
END_OF_BASE_TREE_CODES doesn't exist as an enum or something similarly
usable.
It is something emitted into all-tree.def, like
#include "tree.def"
END_OF_BASE_TREE_CODES
#include "c-family/c-common.def"
#include "ada/gcc-interface/ada-tree.def"
#include "c/c-tree.def"
#include "cp/cp-tree.def"
#include "d/d-tree.def"
#include "m2/m2-tree.def"
#include "objc/objc-tree.def"
but then e.g. tree-core.h uses
/* Codes of tree nodes. */
#define DEFTREECODE(SYM, STRING, TYPE, NARGS) SYM,
#define END_OF_BASE_TREE_CODES LAST_AND_UNUSED_TREE_CODE,
enum tree_code {
#include "all-tree.def"
MAX_TREE_CODES
};
#undef DEFTREECODE
#undef END_OF_BASE_TREE_CODES
and other #include "all-tree.def" similarly define
END_OF_BASE_TREE_CODES to something and then undef afterwards.
Instead of
TREE_CODE (type) >= LAST_AND_UNUSED_TREE_CODE
we could use
TREE_CODE (type) >= NUM_TREE_CODES
if that is what you'd prefer, given the
/* Number of language-independent tree codes. */
#define NUM_TREE_CODES \
((int) LAST_AND_UNUSED_TREE_CODE)
define in tree-core.h.
grep LAST_AND_UNUSED_TREE_CODE *.cc
dwarf2out.cc: >= (unsigned int) LAST_AND_UNUSED_TREE_CODE)
explow.cc: tcode = LAST_AND_UNUSED_TREE_CODE;
expr.cc: gcc_assert (TREE_CODE (exp) < LAST_AND_UNUSED_TREE_CODE);
tree.cc: for (i = ERROR_MARK; i < LAST_AND_UNUSED_TREE_CODE; i++)
tree.cc: if ((int) code1 >= (int) LAST_AND_UNUSED_TREE_CODE)
grep NUM_TREE_CODES *.cc
dwarf2out.cc: gcc_assert ((int)TREE_CODE (decl) > NUM_TREE_CODES);
fold-const.cc: if ((int)TREE_CODE (x) >= NUM_TREE_CODES)
lto-streamer.cc: for (i = 0; i < NUM_TREE_CODES; i++)
tree.cc: gcc_checking_assert (code >= NUM_TREE_CODES);
tree.cc: gcc_checking_assert (code >= NUM_TREE_CODES);
tree.cc: gcc_checking_assert (code >= NUM_TREE_CODES);
tree.cc: gcc_checking_assert (code >= NUM_TREE_CODES);
Jakub