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: Add format string suggestions to -Wformat warnings


On Tue, 14 Aug 2007, Dan Hipschman wrote:

> TYPE_IS_SIZETYPE doesn't work: see the bottom of c_sizeof_or_alignof_type.)
> Simply copying the type nodes seemed like the least-possibly harmful way to do
> this, and I've bootstrapped and run "make -k check" on i686-linux-gnu with no

Going round the back of the type machinery with copy_node is dangerous; 
the type should be a normal variant of the underlying type, just like the 
standard typedefs in the headers, which means using 
build_variant_type_copy.  When sizeof used to return the internal sizetype 
there were many subtle problems caused by this; to avoid returning to such 
problems, the types need to continue to be normal type variants.

At that point, you then need to deal with (unsigned)sizeof(x), which 
should suggest formats for "unsigned" not those for "size_t" even if the 
two happen to be the same (and so the compiler may decide the cast is 
redundant); and typedefs descended from the standard size_t should act 
like size_t.  (If the program used autoconf or similar to ascertain the 
type of size_t and created its own typedef based on that, it's fine as 
long as the formats are correct since then you don't get warnings, but 
there's probably no way to get good format suggestions.)  There's no one 
obvious right answer to how to treat the results of arithmetic such as 
unsigned+size_t.

(You could avoid all the complexity of tracking whether a particular 
expression is ultimately derived from a standard typedef by giving less 
precise suggestions, and then reconsider that tracking later for a 
separate patch.)

dg-excess-errors should only be used very sparingly with xfail.  When 
there are specific diagnostics expected on specific lines, you should 
update the tests to match each new diagnostic individually rather than 
using dg-excess-errors to match them all together.

As well as using inform () to output notes instead of warnings, it might 
make sense to throttle the suggestions to at most one per format string 
(if there are many format warnings from a string, it's probably someone 
missing out an argument or a format rather than systematically getting a 
series of formats wrong).

-- 
Joseph S. Myers
joseph@codesourcery.com


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