This is an archive of the discontinued LLVM Phabricator instance.

[Sema] Consider all format_arg attributes.
ClosedPublic

Authored by Meinersbur on Jun 28 2018, 11:57 AM.

Details

Summary

If a function has multiple format_arg attributes, clang only considers the first it finds (because AttributeLists are in reverse order, it is textual last) and ignores all others.

Loop over all FormatArgAttr to print warnings for all declared format_arg attributes.

For instance, libintl's ngettext (select plural or singular version of format string) has two format_arg attributes.

Diff Detail

Event Timeline

Meinersbur created this revision.Jun 28 2018, 11:57 AM
Meinersbur added inline comments.Jun 28 2018, 11:59 AM
lib/Sema/SemaChecking.cpp
5534

Not sure what should be returned here; To minimize surprises, this returns what the current version would have returned.

Meinersbur edited the summary of this revision. (Show Details)Jun 28 2018, 12:03 PM
aaron.ballman added inline comments.
lib/Sema/SemaChecking.cpp
5523

You can use const auto *FA here instead; the type is spelled out in the initializer.

5536

const auto *

test/Sema/attr-format_arg.c
17

Can you add tests for the other permutations as well? It would also be useful to put the string literals on their own line so that the expected-warning designation matches the specific argument that's being diagnosed. e.g.,

h(
  "%d",
  ""
)
h(
  "", 
  "%d"
)
h(
  "%d",
  "%d"
)
  • Address Aaron's remarks
  • Reinsert test for the change in this patch
This revision is now accepted and ready to land.Jul 3 2018, 3:39 PM
This revision was automatically updated to reflect the committed changes.