Skip to content

Commit e607be1

Browse files
committed
libgccjit: Fix infinite recursion in gt_ggc_mx_lang_tree_node
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.
1 parent 45648c2 commit e607be1

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

gcc/jit/dummy-frontend.cc

+4-3
Original file line numberDiff line numberDiff line change
@@ -972,12 +972,13 @@ struct GTY(()) lang_identifier
972972

973973
/* The resulting tree type. */
974974

975+
/* See lang_tree_node in gcc/c/c-decl.cc. */
975976
union GTY((desc ("TREE_CODE (&%h.generic) == IDENTIFIER_NODE"),
976-
chain_next ("CODE_CONTAINS_STRUCT (TREE_CODE (&%h.generic), TS_COMMON) ? ((union lang_tree_node *) TREE_CHAIN (&%h.generic)) : NULL")))
977-
lang_tree_node
977+
chain_next ("(union lang_tree_node *) jit_tree_chain_next (&%h.generic)"))) lang_tree_node
978978
{
979979
union tree_node GTY((tag ("0"),
980-
desc ("tree_node_structure (&%h)"))) generic;
980+
desc ("tree_node_structure (&%h)")))
981+
generic;
981982
struct lang_identifier GTY((tag ("1"))) identifier;
982983
};
983984

gcc/jit/jit-common.h

+15
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,21 @@ const int NUM_GCC_JIT_TYPES = GCC_JIT_TYPE_FLOAT128 + 1;
9393
9494
End of comment for inclusion in the docs. */
9595

96+
/* See c_tree_chain_next in gcc/c-family/c-common.h. */
97+
static inline tree
98+
jit_tree_chain_next (tree t)
99+
{
100+
/* TREE_CHAIN of a type is TYPE_STUB_DECL, which is different
101+
kind of object, never a long chain of nodes. Prefer
102+
TYPE_NEXT_VARIANT for types. */
103+
if (CODE_CONTAINS_STRUCT (TREE_CODE (t), TS_TYPE_COMMON))
104+
return TYPE_NEXT_VARIANT (t);
105+
/* Otherwise, if there is TREE_CHAIN, return it. */
106+
if (CODE_CONTAINS_STRUCT (TREE_CODE (t), TS_COMMON))
107+
return TREE_CHAIN (t);
108+
return NULL;
109+
}
110+
96111
namespace gcc {
97112

98113
namespace jit {

0 commit comments

Comments
 (0)