Patchwork PATCH trunk: gengtype honoring mark_hook-s inside struct inide union-s

mail settings
Submitter Basile Starynkevitch
Date Oct. 2, 2012, 11:10 a.m.
Message ID <20121002111030.GA1872@hector.lesours>
Download mbox | patch
Permalink /patch/188453/
State New
Headers show


Basile Starynkevitch - Oct. 2, 2012, 11:10 a.m.
Hello All,

As I observed in and in the mark_hook GTY annotation is 
sometimes incorrectly ingored by gengtype.

The example in demonstrates
that incorrect behavior of gengtype (both with gengtype from GCC 4.7, 
and with the current trunk's gengtype). For simplicity, here is it again:

   /* file tmarkh.h */
   #define MYUTAG 1
   union GTY ((desc("%0.u_int"))) myutest_un {
     int GTY((skip)) u_int;
     struct mytest_st GTY ((tag("MYUTAG"))) u_mytest;

   static GTY(()) union myutest_un *myutestptr;

   static inline void mymarker(struct mytest_st*s)
     s->myflag = 1;
   /* eof tmarkh.h */
when running gengtype (the one from the trunk, or the gcc-4.7 one) with
  gengtype  -D -v -r gtype.state -P _g-tmarkh.h tmarkh.h
you can observe that the generated _g-tmarkh.h don't contain any call to 
mymarker. If the static variable (here myutestptr) is declared with the 
struct mytest_st* type, the marker is emitted.

The reason of that bug is that for GTY-ed union members which are themselves 
GTY-ed struct, the marking of the nested struct is generated inline (for the union)
and in that case the mark_hook annotation was not used.

The attached patch to trunk svn rev 191972 solves this issue
(with it, the generated _g-tmarkh.h is correctly calling mymarker).

The gcc/ChangeLog entry is:

2012-10-02  Basile Starynkevitch  <>

	* gengtype.c (walk_type): Emit mark_hook when inside a
          struct of a union member.


Ok for trunk?

Laurynas Biveinis - Oct. 3, 2012, 9:21 a.m.
Hello Basile -

> 2012-10-02  Basile Starynkevitch  <>
>         * gengtype.c (walk_type): Emit mark_hook when inside a
>           struct of a union member.

Can you send me off-list the gengtype output before and after the fix?

+       const char *structmarkhook = NULL;

struct_mark_hook or just mark_hook please.

+           oprintf (d->of, "%*s/*structmarkhook %s */ %s (&%s));\n",
+                    d->indent, "", t->u.s.tag,  structmarkhook, oldval);

No need to output the comment.



Index: gcc-trunk-bstarynk/gcc/gengtype.c
--- gcc-trunk-bstarynk/gcc/gengtype.c	(revision 191972)
+++ gcc-trunk-bstarynk/gcc/gengtype.c	(working copy)
@@ -2810,6 +2810,7 @@  walk_type (type_p t, struct walk_type_data *d)
 	const char *oldval = d->val;
 	const char *oldprevval1 = d->prev_val[1];
 	const char *oldprevval2 = d->prev_val[2];
+	const char *structmarkhook = NULL;
 	const int union_p = t->kind == TYPE_UNION;
 	int seen_default_p = 0;
 	options_p o;
@@ -2833,7 +2834,14 @@  walk_type (type_p t, struct walk_type_data *d)
 	  if (!desc && strcmp (o->name, "desc") == 0
 	      && o->kind == OPTION_STRING)
 	    desc = o->info.string;
+	  else if (!structmarkhook && strcmp(o->name, "mark_hook") == 0
+		   && o->kind == OPTION_STRING)
+	    structmarkhook = o->info.string;
+	if (structmarkhook) 
+	    oprintf (d->of, "%*s/*structmarkhook %s */ %s (&%s));\n",
+		     d->indent, "", t->u.s.tag,  structmarkhook, oldval);
 	d->prev_val[2] = oldval;
 	d->prev_val[1] = oldprevval2;
 	if (union_p)