Skip to content

Commit

Permalink
libgccjit: Fix infinite recursion in gt_ggc_mx_lang_tree_node
Browse files Browse the repository at this point in the history
This issue happened when compiling rustc with rustc_codegen_gcc, more
specifically when compiling its rustc_parse crate.

gcc/jit/
	PR target/105827
	* dummy-frontend.cc: Fix lang_tree_node.
	* jit-common.h: New function (jit_tree_chain_next) used by
	lang_tree_node.
  • Loading branch information
antoyo committed Jan 15, 2025
1 parent 45648c2 commit e607be1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
7 changes: 4 additions & 3 deletions gcc/jit/dummy-frontend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -972,12 +972,13 @@ struct GTY(()) lang_identifier

/* The resulting tree type. */

/* See lang_tree_node in gcc/c/c-decl.cc. */
union GTY((desc ("TREE_CODE (&%h.generic) == IDENTIFIER_NODE"),
chain_next ("CODE_CONTAINS_STRUCT (TREE_CODE (&%h.generic), TS_COMMON) ? ((union lang_tree_node *) TREE_CHAIN (&%h.generic)) : NULL")))
lang_tree_node
chain_next ("(union lang_tree_node *) jit_tree_chain_next (&%h.generic)"))) lang_tree_node
{
union tree_node GTY((tag ("0"),
desc ("tree_node_structure (&%h)"))) generic;
desc ("tree_node_structure (&%h)")))
generic;
struct lang_identifier GTY((tag ("1"))) identifier;
};

Expand Down
15 changes: 15 additions & 0 deletions gcc/jit/jit-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,21 @@ const int NUM_GCC_JIT_TYPES = GCC_JIT_TYPE_FLOAT128 + 1;
End of comment for inclusion in the docs. */

/* See c_tree_chain_next in gcc/c-family/c-common.h. */
static inline tree
jit_tree_chain_next (tree t)
{
/* TREE_CHAIN of a type is TYPE_STUB_DECL, which is different
kind of object, never a long chain of nodes. Prefer
TYPE_NEXT_VARIANT for types. */
if (CODE_CONTAINS_STRUCT (TREE_CODE (t), TS_TYPE_COMMON))
return TYPE_NEXT_VARIANT (t);
/* Otherwise, if there is TREE_CHAIN, return it. */
if (CODE_CONTAINS_STRUCT (TREE_CODE (t), TS_COMMON))
return TREE_CHAIN (t);
return NULL;
}

namespace gcc {

namespace jit {
Expand Down

0 comments on commit e607be1

Please sign in to comment.