[PATCH] D33976: [clang] Fix format specifiers fixits

Alexander Shaposhnikov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 6 20:00:23 PDT 2017


alexshap created this revision.

This diff fixes printf "fixits" in the case when there is a wrapping macro and
the format string needs multiple replacements. 
In the presence of a macro there was an extra logic in EditedSource.cpp
to handle multiple uses of the same macro argument 
(see the old comment inside EditedSource::canInsertInOffset)
which was mistriggering when the argument was used only once 
but required multiple adjustments), as a result the "fixit" was breaking down the format string
by dropping the second format specifier, i.e. 
Log1("test 4: %s %s", getNSInteger(), getNSInteger()) 
was getting replaced with 
Log1("test 4: %ld ", (long)getNSInteger(), (long)getNSInteger()) 
(if one removed the macro and used printf directly it would work fine).
In this diff we track the location where the macro argument is used and 
(as it was before) the modifications originating from all the locations except the first one are rejected,
but multiple changes are allowed.

Test plan: make check-all


Repository:
  rL LLVM

https://reviews.llvm.org/D33976

Files:
  include/clang/Edit/EditedSource.h
  lib/Edit/EditedSource.cpp
  test/FixIt/fixit-format-darwin.m

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D33976.101663.patch
Type: text/x-patch
Size: 6252 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170607/4a3501c9/attachment-0001.bin>


More information about the cfe-commits mailing list