This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: correct way of having a function pointer inside a GTY()-ed struct?


On Sat, Mar 21, 2009 at 2:19 PM, Basile STARYNKEVITCH
<basile@starynkevitch.net> wrote:
> Hello All,
>
> Richard Guenther wrote:
>>
>> On Sat, Mar 21, 2009 at 1:17 PM, Basile STARYNKEVITCH
>> <basile@starynkevitch.net> wrote:
>>
>>>
>>> Hello All,
>>>
>>> What is the politically correct way of having an ignored function pointer
>>> inside a GTY-ed struct?
>>>
>
> To be more precise, I have
>
> typedef basilys_ptr_t basilysroutfun_t (basilysclosure_ptr_t closp_,
> ? ? ? ? ? ? ? ? ? basilys_ptr_t firstargp_,
> ? ? ? ? ? ? ? ? ? const char xargdescr_[],
> ? ? ? ? ? ? ? ? ? union basilysparam_un *xargtab_,
> ? ? ? ? ? ? ? ? ? const char xresdescr_[],
> ? ? ? ? ? ? ? ? ? union basilysparam_un *xrestab_);
>
>>> Of course, the function pointer is obviously GTY ((skip))-ed.
>>>
>>> In the MELT branch (file gcc/basilys.h rev144985) I have
>>> // notice that FLEXIBLE_DIM is a macro expanding to empty
>>>
>>> #define BASILYS_ROUTDESCR_LEN 96
>>> #define BASILYS_ROUTADDR_LEN ?(1 + (2*sizeof (basilysroutfun_t *))/
>>> sizeof
>>> (long))
>>>
>>> struct basilysroutine_st
>>> GTY (())
>>> {
>>> ?basilysobject_ptr_t discr;
>>> ?char routdescr[BASILYS_ROUTDESCR_LEN];
>>> ?long GTY ((skip)) routaddr[BASILYS_ROUTADDR_LEN];
>>> ?basilys_ptr_t routdata;
>>> ?unsigned nbval;
>>> ?basilys_ptr_t GTY ((length ("%h.nbval"))) tabval[FLEXIBLE_DIM];
>>> };
>>>
>>> /* unsafely set inside the basilysroutine_st pointed by Rptr the
>>> ?routine function pointer to Rout */
>>> #define BASILYS_ROUTINE_SET_ROUTCODE(Rptr,Rout) do { ? ? ? ? ? ?\
>>> ?(*(basilysroutfun_t**)((struct basilysroutine_st*)(Rptr))->routaddr)
>>> ?\
>>> ? = (Rout); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?\
>>>
>>
>> This violates C aliasing rules. ?As it is a macro I have no idea what Rptr
>> and
>> Rout point to and thus cannot provide any advice. ?Please consider
>> making such *_SET macros inline functions instead (not that this would
>> fix this particular bug).
>
> I just need to set a function pointer inside a GTY-ed struct. Since gengtype
> does not allow these, I tried some trick to circumvent gengtype limitations.
>
> Any advices on making that cleaner are welcome.
>
> So my point is that I want to put inside the GTY-ed struct basilysroutine_st
> an ignored (I mean GTY((skip))-ed) field called routaddr which is a function
> pointer
> (function of type basilysroutfun_t - which is typedef-ed above).
>
> How can I achieve that, in the cleanest way possible?

Just do it and fix whatever causes that not to work?!

Richard.

> 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} ***
>
>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]