[PATCH] D131057: [Sema] -Wformat: support C23 format specifier %b %B

Fangrui Song via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 3 12:41:35 PDT 2022

MaskRay added a comment.

In D131057#3697265 <https://reviews.llvm.org/D131057#3697265>, @enh wrote:

>> I think making scanf in the same patch makes sense. Let me check existing tests...
> fwiw, most of the libcs seem to have been doing these separately because scanf is harder. i hope to have bionic's scanf done this week though.
> (note in case you haven't already that there is no %B for scanf, just %b...)

Thanks for the reminder:)  I subscribed to https://www.openwall.com/lists/libc-coord/2022/08/ but working on this issue led me to read the discussion:)

`scanf("%B", i); // expected-warning{{invalid conversion specifier 'B'}}` tests this.

In D131057#3697095 <https://reviews.llvm.org/D131057#3697095>, @dim wrote:

>> GCC 12 -Wformat -pedantic emits a warning:
>>   warning: ISO C17 does not support the ‘%b’ gnu_printf format [-Wformat=]
>> The behavior is not ported (and it's unclear to me how to implement it).
> If you really want this, I think it can be implemented by looking at `LangOpts::LangStd`.

Something like `!getLangOpts().C2X` I suppose, but I do not find how to check both `-Wformat` and `-Wpedantic`.
Also, for the nature of the diagnostic, I think something in TableGen like `def ext_... InGroup<C2x>` would make sense but using a C23/C2x related -W option would deviate from the GCC behavior.
ISTM adding the diagnostic (even if we do) is not so necessary in this patch.

  rG LLVM Github Monorepo



More information about the cfe-commits mailing list