[PATCH] D27165: Add format_dynamic_key_arg attribute to improve "-Wformat" warnings for functions that load the formatting string dynamically based on a key value

Alex Lorenz via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 28 07:59:39 PST 2016


arphaman created this revision.
arphaman added reviewers: aaron.ballman, manmanren.
arphaman added a subscriber: cfe-commits.
arphaman set the repository for this revision to rL LLVM.

This patch adds a new ``format_dynamic_key_arg``. It's intended to be used instead of ``format_arg`` for methods/functions that load the formatting string from some external source based on the given key value. The attribute tells Clang that it has to avoid ``-Wformat`` warnings when key strings have no formatting specifiers. Otherwise it tells Clang that it can assume that the key strings use the same formatting layout as the external formatting string values (i.e. Clang can perform the normal ``-Wformat`` related checks).

This attribute is useful for certain Objective-C methods like ``NSBundle.localizedStringForKey`` that load the values dynamically based on a specified key value.


Repository:
  rL LLVM

https://reviews.llvm.org/D27165

Files:
  include/clang/Analysis/Analyses/FormatString.h
  include/clang/Basic/Attr.td
  include/clang/Basic/AttrDocs.td
  lib/Analysis/PrintfFormatString.cpp
  lib/Sema/SemaChecking.cpp
  lib/Sema/SemaDeclAttr.cpp
  test/Sema/attr-format_arg.c
  test/SemaObjC/format-strings-objc.m

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D27165.79404.patch
Type: text/x-patch
Size: 17620 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161128/752cd42a/attachment.bin>


More information about the cfe-commits mailing list