This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Is it possible to make gcc detect whether printf prints floating point numbers?
On Tue, 12 Jun 2012, Bin.Cheng wrote:
> >> I noticed that GCC now can check format string of printf functions, so
> >> I am wondering if it is possible to take advantage of this utility, by
> >> making gcc detect whether printf prints floating point number and then
> >> generate assembly directive in backend to pull in floating point
> >> functions only if necessary.
> >
> > Obviously this won't help if the program is using functions such as
> > vprintf to print things with variable format strings....
> One method is to analyze the type of arguments when format strings are
> varying. Though this method might fail when user trying to output a
> "long long" type int with conversion specifier "%f", I think it's not
> a big deal.
That method won't help for vprintf (unless you do something more
complicated and interprocedural) since then you have just a (probably
nonconstant) format strict and a (definitely nonconstant) va_list so don't
know the types of the arguments at all.
--
Joseph S. Myers
joseph@codesourcery.com