This is an archive of the discontinued LLVM Phabricator instance.

[libTooling] Transformer: refine `SourceLocation` specified as anchor of changes.
ClosedPublic

Authored by ymandel on Aug 23 2019, 7:01 AM.

Details

Summary

Every change triggered by a rewrite rule is anchored at a particular location in
the source code. This patch refines how that location is chosen and defines it
as an explicit function so it can be shared by other Transformer implementations.

This patch was inspired by a bug found by a clang tidy, wherein two changes were
anchored at the same location (the expansion loc of the macro) resulting in the
discarding of the second change.

Diff Detail

Repository
rL LLVM

Event Timeline

ymandel created this revision.Aug 23 2019, 7:01 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 23 2019, 7:01 AM
ymandel updated this revision to Diff 216838.Aug 23 2019, 7:04 AM

comment tweaks.

gribozavr accepted this revision.Aug 23 2019, 10:16 AM
gribozavr added inline comments.
clang/lib/Tooling/Refactoring/Transformer.cpp
197 ↗(On Diff #216838)

This comment was moved into the function and now looks out of place here.

This revision is now accepted and ready to land.Aug 23 2019, 10:16 AM
ymandel updated this revision to Diff 216921.Aug 23 2019, 12:17 PM
ymandel marked 2 inline comments as done.

comments tweaks.

I'm having second thoughts about this -- I prefer the approach I ended up taking in https://reviews.llvm.org/D66676, which is subtly different.

However, getRuleMatchLoc() will be useful a different purpose: when only reporting a diagnostic, with no corresponding changes. So, I plan to rework this into two revisions: one to match https://reviews.llvm.org/D66676 (and keep the tests esssentially as they are) and one to add getRuleMatchLoc for future use. I can also make both changes in the same revision, if you prefer.

clang/lib/Tooling/Refactoring/Transformer.cpp
197 ↗(On Diff #216838)

removed in both places. Even in the function, it didn't add anything meaningful to the assert() itself.

So, I plan to rework this into two revisions: one to match https://reviews.llvm.org/D66676 (and keep the tests esssentially as they are) and one to add getRuleMatchLoc for future use.

That SGTM.

I don't have an opinion about whether they should be separate revisions or not.

ymandel updated this revision to Diff 222177.Sep 27 2019, 8:15 AM

reworked to follow same scheme as clang-tidy version, per discussion.

So, I plan to rework this into two revisions: one to match https://reviews.llvm.org/D66676 (and keep the tests esssentially as they are) and one to add getRuleMatchLoc for future use.

That SGTM.

I don't have an opinion about whether they should be separate revisions or not.

Reworked, per our discussion. I kept it in one revision, because I ended up useing the new function in this code (for error reporting).

ymandel edited the summary of this revision. (Show Details)Sep 27 2019, 8:23 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptSep 27 2019, 8:26 AM