Add a format warning for "%p" with non-void* args
authorSeth Cantrell <seth.cantrell@gmail.com>
Wed, 4 Mar 2015 03:12:10 +0000 (03:12 +0000)
committerSeth Cantrell <seth.cantrell@gmail.com>
Wed, 4 Mar 2015 03:12:10 +0000 (03:12 +0000)
commitb480296e6cb4a2cc5d5f588e35d4148f8770fea9
treec7a8c0e3e3c63e4f8dc835d884b3c948d7c3cf16
parent9412d63f683346e010261662acf97e8c10cb8d03
Add a format warning for "%p" with non-void* args

GCC -pedantic produces a format warning when the "%p" specifier is used with
arguments that are not void*. It's useful for portability to be able to
catch such warnings with clang as well. The warning is off by default in
both gcc and with this patch. This patch enables it either when extensions
are disabled with -pedantic, or with the specific flag -Wformat-pedantic.

The C99 and C11 specs do appear to require arguments corresponding to 'p'
specifiers to be void*: "If any argument is not the correct type for the
corresponding conversion specification, the behavior is undefined."
[7.19.6.1 p9], and of the 'p' format specifier "The argument shall be a
pointer to void." [7.19.6.1 p8]

Both printf and scanf format checking are covered.

llvm-svn: 231211
clang/include/clang/Analysis/Analyses/FormatString.h
clang/include/clang/Basic/DiagnosticGroups.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Analysis/FormatString.cpp
clang/lib/Sema/SemaChecking.cpp
clang/test/SemaCXX/format-strings-0x.cpp