On Wed, Oct 03, 2012 at 12:21:02PM +0300, Laurynas Biveinis wrote:
> Hello Basile -
>
> > 2012-10-02 Basile Starynkevitch <[email protected]>
> >
> > * 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?
I messed something, the example I did send was wrong. Let's start all over
again.
Consider the following file
(I named this example on purpose differently than in the previous message)
####################
/* file basilemarkh.h */
struct GTY ((mark_hook("mymarker"))) mytest_st {
int myflag;
tree mytree;
gimple mygimple;
};
#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 basilemarkh.h */
###################
With the gengtype from 4.7 in Debian/Sid/AMD64 (a 4.7.2 I believe)
/usr/lib/gcc/x86_64-linux-gnu/4.7/gengtype -D -v \
-r /usr/lib/gcc/x86_64-linux-gnu/4.7/gtype.state \
-P _g-4.7-basilemarkh.h basilemarkh.h
#### from generated _g-4.7-basilemarkh.h
/* functions code */
void
gt_ggc_mx_myutest_un (void *x_p)
{
union myutest_un * const x = (union myutest_un *)x_p;
if (ggc_test_and_set_mark (x))
{
switch ((*x).u_int)
{
case MYUTAG: //// ###### no mark hook here, should have a call to
mymarker
gt_ggc_m_9tree_node ((*x).u_mytest.mytree);
gt_ggc_m_18gimple_statement_d ((*x).u_mytest.mygimple);
break;
default:
break;
}
}
}
### end of excerpt from generated _g-4.7-basilemarkh.h
With the gengtype from unpatched trunk svn rev 192031 the emitted
gt_ggc_mx_myutest_un is exactly the same.
Of course the //// ### comment above has been added manually by me Basile.
So I applied and I am proposing the following patch to gcc trunk 192031
(Laurynas, I did take your remarks into account)
##### patch to trunk
Index: gcc/gengtype.c
===================================================================
--- gcc/gengtype.c (revision 192031)
+++ 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 *struct_mark_hook = 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 (!struct_mark_hook && strcmp (o->name, "mark_hook") == 0
+ && o->kind == OPTION_STRING)
+ struct_mark_hook = o->info.string;
+ if (struct_mark_hook)
+ oprintf (d->of, "%*s%s (&%s));\n",
+ d->indent, "", struct_mark_hook, oldval);
+
d->prev_val[2] = oldval;
d->prev_val[1] = oldprevval2;
if (union_p)
##### end of patch
with the following ChangeLog entry
##### gcc/ChangeLog entry
2012-10-03 Basile Starynkevitch <[email protected]>
* gengtype.c (walk_type): Emit mark_hook when inside a
struct of a union member.
##### end of gcc/ChangeLog entry
If you apply my proposed patch the emitted function is
### from generated _gtrunk-basilemarkh.h with my patch to gengtype.c
/* functions code */
void
gt_ggc_mx_myutest_un (void *x_p)
{
union myutest_un * const x = (union myutest_un *)x_p;
if (ggc_test_and_set_mark (x))
{
switch ((*x).u_int)
{
case MYUTAG:
mymarker (&(*x).u_mytest));
gt_ggc_m_9tree_node ((*x).u_mytest.mytree);
gt_ggc_m_18gimple_statement_d ((*x).u_mytest.mygimple);
break;
default:
break;
}
}
}
#### end of excerpt from generated _gtrunk-basilemarkh.h
If you just use the gengtype from trunk 192031 without my patch
you get the same code as from gcc-4.7's gengtype:
#### from generated _g192031-basilemarkh.h
void
gt_ggc_mx_myutest_un (void *x_p)
{
union myutest_un * const x = (union myutest_un *)x_p;
if (ggc_test_and_set_mark (x))
{
switch ((*x).u_int)
{
case MYUTAG:
gt_ggc_m_9tree_node ((*x).u_mytest.mytree);
gt_ggc_m_18gimple_statement_d ((*x).u_mytest.mygimple);
break;
default:
break;
}
}
}
### end of excerpt from generated _g192031-basilemarkh.h
Is my patch here ok for trunk?
Regards.
--
Basile STARYNKEVITCH http://starynkevitch.net/Basile/
email: basile<at>starynkevitch<dot>net mobile: +33 6 8501 2359
8, rue de la Faiencerie, 92340 Bourg La Reine, France
*** opinions {are only mines, sont seulement les miennes} ***