This is the mail archive of the gcc-patches@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: [PATCH, C] Fix format warnings


On Tue, 26 Apr 2005, Joseph S. Myers wrote:

> On Tue, 26 Apr 2005, Richard Guenther wrote:
>
> > This patch makes the C frontend not warn that a format string
> > is not literal for things like
> >
> >    char *a = "Foo";
> >    printf(&a[0]);
>
> But the format checking isn't dataflow sensitive, so of course this (char
> * as opposed to char *const) should warn.  It's only in cases where we
> genuinely know the value of the variable - if the variable itself is const
> - that we can avoid this warning.  (In fact I think we only try to avoid
> it for const array variables at present, not char *const or const char
> *const ones initialized by string constants, although we could do those as
> well.)
>
> Start with the genuine testcase for gcc.dg/format that fails without the
> patch and passes with it.  What is the real testcase for the problem you
> are trying to address?  And shouldn't you allow constants other than 0,
> setting offset appropriately as is already done if the format argument is
> a PLUS_EXPR, with tests for nonzero constants?

Yes, sorry - the problems I'm trying to solve is the fallout from
making C emit &a[0] instead of &a.  Indeed, gcc.dg/format/plus-1.c
still fails with this patch as it is exactly the PLUS_EXPR case
that is not handled.

Note that rth suggested "fixing" the frontend(s) to emit &a[0] rather
than &a instead of having fold doing this canonicalization.  I'm
curious what you as a C frontend maintainer think of this ;)

Richard.

--
Richard Guenther <richard dot guenther at uni-tuebingen dot de>
WWW: http://www.tat.physik.uni-tuebingen.de/~rguenth/


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