[Sema] -Wformat: support C23 format specifier %b %B
authorFangrui Song <i@maskray.me>
Thu, 4 Aug 2022 17:26:31 +0000 (10:26 -0700)
committerFangrui Song <i@maskray.me>
Thu, 4 Aug 2022 17:26:31 +0000 (10:26 -0700)
commit88501dc74911b00186298fe1fffe8dfb1f09b1c1
tree3006a14e5de6a29b65e6b98b80e1fcd5490f7b23
parent22df238d4a642a4553ebf7b91325189be48b139d
[Sema] -Wformat: support C23 format specifier %b %B

Close #56885: WG14 N2630 added %b to fprintf/fscanf and recommended %B for
fprintf. This patch teaches -Wformat %b for the printf/scanf family of functions
and %B for the printf family of functions.

glibc 2.35 and latest Android bionic added %b/%B printf support. From
https://www.openwall.com/lists/libc-coord/2022/07/ no scanf support is available
yet.

Like GCC, we don't test library support.

GCC 12 -Wformat -pedantic emits a warning:

> warning: ISO C17 does not support the â€˜%b’ gnu_printf format [-Wformat=]

The behavior is not ported.

Note: `freebsd_kernel_printf` uses %b differently.

Reviewed By: aaron.ballman, dim, enh

Differential Revision: https://reviews.llvm.org/D131057
clang/docs/ReleaseNotes.rst
clang/include/clang/AST/FormatString.h
clang/lib/AST/FormatString.cpp
clang/lib/AST/PrintfFormatString.cpp
clang/lib/AST/ScanfFormatString.cpp
clang/test/Sema/format-strings-fixit.c
clang/test/Sema/format-strings-scanf.c
clang/test/Sema/format-strings.c
clang/test/SemaObjC/format-strings-objc.m