Hi, all.

I am tying to fix an issue with a global variable in the parallel gcc
project. For this, I am trying to move some global variables from
tree-ssa-operands to struct function. One of this variable is a
vec<tree*> type, and gengtype doesn't look so happy with it.

In this context, I am trying to add support to vec<tree*> to gengtype.
Therefore, I first fixed a problem where gengtype couldn't find the
tree union by:

diff --git a/gcc/gengtype.c b/gcc/gengtype.c
index 53317337cf8..6f4c77020ea 100644
--- a/gcc/gengtype.c
+++ b/gcc/gengtype.c
@@ -638,7 +638,10 @@ create_user_defined_type (const char *type_name, struct fil
eloc *pos)
              /* Strip off the first '*' character (and any subsequent text). */
              *(field_name + offset_to_star) = '\0';
 
-             arg_type = find_structure (field_name, TYPE_STRUCT);
+             arg_type = resolve_typedef (field_name, pos);
+             if (!arg_type)
+               arg_type = find_structure (field_name, TYPE_STRUCT);
+
              arg_type = create_pointer (arg_type);
            }
          else

After this patch, gengtype seems to correctly detect vec<tree*> types,
but then I face linking issues. At first, the compiler could not find
gt_ggc_mx (vec<T> *v) and gt_pch_mx (vec<T> *v), therefore I implemented
them both in gcc/vec.h:

diff --git a/gcc/vec.h b/gcc/vec.h
index 091056b37bc..dfa744b684e 100644
--- a/gcc/vec.h
+++ b/gcc/vec.h
@@ -1306,6 +1306,15 @@ vec<T, A, vl_embed>::quick_grow_cleared (unsigned len)
     vec_default_construct (address () + oldlen, growby);
 }
 
+template<typename T>
+void
+gt_ggc_mx (vec<T> *v)
+{
+  extern void gt_ggc_mx (T &);
+  for (unsigned i = 0; i < v->length (); i++)
+    gt_ggc_mx ((*v)[i]);
+}
+
 /* Garbage collection support for vec<T, A, vl_embed>.  */
 
 template<typename T>
@@ -1328,6 +1337,15 @@ gt_ggc_mx (vec<T, va_gc_atomic, vl_embed> *v 
ATTRIBUTE_UNUSED)
 
 /* PCH support for vec<T, A, vl_embed>.  */
 
+template<typename T>
+void
+gt_pch_nx (vec<T> *v)
+{
+  extern void gt_pch_nx (T &);
+  for (unsigned i = 0; i < v->length (); i++)
+    gt_pch_nx ((*v)[i]);
+}
+
 template<typename T, typename A>
 void
 gt_pch_nx (vec<T, A, vl_embed> *v)
@@ -1337,6 +1355,14 @@ gt_pch_nx (vec<T, A, vl_embed> *v)
     gt_pch_nx ((*v)[i]);
 }
 
+template<typename T>
+void
+gt_pch_nx (vec<T *> *v, gt_pointer_operator op, void *cookie)
+{
+  for (unsigned i = 0; i < v->length (); i++)
+    op (&((*v)[i]), cookie);
+}
+
template<typename T, typename A>
 void
 gt_pch_nx (vec<T *, A, vl_embed> *v, gt_pointer_operator op, void *cookie)
@@ -1354,6 +1380,15 @@ gt_pch_nx (vec<T, A, vl_embed> *v, gt_pointer_operator 
op, void *cookie)
     gt_pch_nx (&((*v)[i]), op, cookie);
 }
 
+template<typename T>
+void
+gt_pch_nx (vec<T> *v, gt_pointer_operator op, void *cookie)
+{
+  extern void gt_pch_nx (T *, gt_pointer_operator, void *);
+  for (unsigned i = 0; i < v->length (); i++)
+    gt_pch_nx (&((*v)[i]), op, cookie);
+}
+

After that, I get linking errors because the linker can not find
gt_ggc_mx (tree *&x) nor void gt_pch_nx (tree *&x). The thing
is: it doesn't matter where I implement them, or if I declare
them inline. I always get a linking error one way or another.

Therefore, what should I do to correctly implement the support
for vec<tree*> types?

Thank you,
Giuliano.

Reply via email to