> > I tried to annotate `cached_wd` via GTY((..)) as on first glance it seems > > the gc mistakenly re-uses it, but the `gengtype` generated state file never > > picks this variable up. > > Have you tried moving the variable to the top level and annotating it > with GTY ((cache))? > > I believe gengtype will emit code to clear such variables during > garbage collection, avoiding the issue. Thanks, `static GTY(()) const char* cached_wd = NULL;` outside the function fixes it. (style: Is directly outside the function Ok, or should this be moved to the top of the file?) Now gtype.state picks it up and the final object contains the correct string.