[cfe-commits] r145697 - in /cfe/trunk: include/clang/Analysis/Analyses/FormatString.h lib/Analysis/FormatString.cpp lib/Analysis/PrintfFormatString.cpp lib/Sema/SemaChecking.cpp test/Sema/format-strings-int-typedefs.c

Hans Wennborg hans at chromium.org
Tue Dec 6 05:44:53 PST 2011


On Mon, Dec 5, 2011 at 7:51 PM, Richard Smith <richard at metafoo.co.uk> wrote:
> I'm not sure I agree that mentioning size_t is not great. Since %zu means 'an
> unsigned integer the same width as size_t', it would be strange to not mention
> size_t. One particular case where I'd like to see a good diagnostic is where
> the 'real' size_t is not in scope, but an incorrect user-defined size_t is:
>
> a.c:4:13: warning: conversion specifies type 'size_t' (aka 'unsigned int') but
> the argument has type 'size_t' (aka 'unsigned long long') [-Wformat]
>  printf("%zu", sz);
>          ~~^   ~~
>          %llu

Attaching a new patch which extends
analyze_format_string::ArgTypeResult with a new kind of result which
has both an expected type (e.g. unsigned int) and a name for the type
(e.g. size_t).

This way, we can always refer to size_t, independently of whether it's
in scope or not, both by name and actual type.

Please take a look.

Thanks,
Hans
-------------- next part --------------
A non-text attachment was scrubbed...
Name: format-strings-int-typedefs2.diff
Type: text/x-patch
Size: 8607 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20111206/d4f0a76b/attachment.bin>


More information about the cfe-commits mailing list