On Thu, 2012-10-18 at 22:33 +0200, Basile Starynkevitch wrote: > Hello > > I'm coding in MELT the ex06/ of https://github.com/bstarynk/melt-examples/ > which should typecheck calls to variadic functions json_pack & json_unpack > from http://www.digip.org/jansson (a JSON library in C). > > I'm working on a MELT pass on Gimple/SSA after phiopt (maybe that place is > wrong?) > > I don't understand well how to check that a given Gimple argument is a string. > I was thinking of using useless_type_conversion_p or types_compatible_p on > the TREE_TYPE of some POINTER_TYPE with char_type_node, but it seems to not > work as I would expect > > How would you (in C++ or C for a 4.6) code such a test (that argument 2 of > some GIMPLE_CALL is a string, ie. a char* in C parlance)? > > (I'm coding in MELT, but I am not asking a MELT specific question; I have > hard time understanding how that should be coded in C++).
FWIW I've written a type-checker for variadic arguments in my Python plugin; this probably won't help you but the python code can be seen here: http://git.fedorahosted.org/cgit/gcc-python-plugin.git/tree/libcpychecker/formatstrings.py (it checks usage of the CPython API) In theory I'm looking up the "char" type via integer_types[itk_char], then getting the pointer type via build_pointer_type() to get "char *", then comparing for pointer equality. But it got a *lot* more complicated than that when handling special cases (e.g. a typedef that's a char is also acceptable). > Or where is the typechecking for __attribute__((format(printf))) functions > done in the GCC source tree? I believe it's within gcc/c-family/c-format.c Hope this is helpful Dave