[PATCH] implement a -Wformat-pedantic warning

Seth Cantrell seth.cantrell at gmail.com
Tue Mar 3 22:30:44 PST 2015


There were test failures on a number of buildbots which for some reason don't reproduce on my system. E.g. clang/test/Sema/format-strings-scanf.c and clang/test/Sema/format-strings-gnu.c pass for me.

Fortunately I was able to identify the issue using the buildbots' test output and so I committed a change (r231213) to fix the buildbots. At the moment 5 of the 10 bots broken by my previous change have completed a build with my newest change and it does seem to have fixed the issue.

As before, this patch passed running ninja clang-test (on my development platform...), and was formatted via clang-format.

The change I committed is attached for your convenience.

- Seth


> On Mar 3, 2015, at 8:21 PM, Richard Smith <richard at metafoo.co.uk> wrote:
> 
> On Tue, Mar 3, 2015 at 4:51 PM, Seth Cantrell <seth.cantrell at gmail.com <mailto:seth.cantrell at gmail.com>> wrote:
> Does this patch look okay for me to go ahead and commit?
> 
> Yes, LGTM, thanks.
>  
> Thanks,
> Seth
> 
> 
>> On Feb 27, 2015, at 8:30 PM, Seth Cantrell <seth.cantrell at gmail.com <mailto:seth.cantrell at gmail.com>> wrote:
>> 
>> 
>>> On Feb 26, 2015, at 8:28 PM, Seth Cantrell <seth.cantrell at gmail.com <mailto:seth.cantrell at gmail.com>> wrote:
>>> 
>>> 
>>>> On Feb 26, 2015, at 7:24 PM, Richard Smith <richard at metafoo.co.uk <mailto:richard at metafoo.co.uk>> wrote:
>>>> 
>>>> On Thu, Feb 26, 2015 at 4:01 PM, Seth Cantrell <seth.cantrell at gmail.com <mailto:seth.cantrell at gmail.com>> wrote:
>>>> This enables a warning corresponding to gcc's warning of using %p modifiers with non-void* pointers, and to the printf/scanf specs which require void*.
>>>> 
>>>> The warning is on by default for -Weverything users, off by default for others. It can be enabled with -pedantic or -Wformat-pedantic. It's not enabled by -Wformat.
>>>> 
>>>> From a high level, this seems like a good approach to the problem, thanks.
>>>>  
>>>> The patch includes tests and the clang-test target passes with this patch applied to a recent clang revision.
>>>> 
>>>> I used clang-format to format my changes and the patch includes cleanup of a few trailing whitespace issues that were near my changes.
>>>> 
>>>> See also the email thread at: http://lists.cs.uiuc.edu/pipermail/cfe-dev/2015-February/041714.html <http://lists.cs.uiuc.edu/pipermail/cfe-dev/2015-February/041714.html>
>>>> 
>>>> It doesn't seem ideal to call matchesType twice to find out which diagnostic to issue; have you considered returning an enum { Match, NoMatchPedantic, NoMatch }; or similar instead?
>>> 
>>> That did initially occur to me but I saw the matchesType usages in a few other locations and wanted to keep a compatible API. It wasn't clear, for example, whether the NoMatchPedantic option should convert to true or false of if I should even support the current usage rather than make every use check for each condition explicitly.
>>> 
>>> I will go back and more carefully review the other usages to see what refactoring I need to do.
>>> 
>>> Thanks,
>>> Seth
>> 
>> 
>> Here's an updated patch which takes the suggested approach. I did keep the API compatible, so the matchesType's return value for mismatches converts to false and the value for matches and pedantic mismatches converts to true. This way most uses are unchanged and the code only distinguishes between matches and pedantic mismatches in four checks.
>> 
>> <0001-Add-a-format-warning-for-p-with-non-void-args.patch>
> 
> 
> 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150304/3023ed1f/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-AT.isValid-should-come-before-AT.matchesType.patch
Type: application/octet-stream
Size: 3718 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150304/3023ed1f/attachment.obj>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150304/3023ed1f/attachment-0001.html>


More information about the cfe-commits mailing list