This is an archive of the discontinued LLVM Phabricator instance.

[ASTMatchers] Fix child traversal over range-for loops
ClosedPublic

Authored by steveire on Jan 4 2021, 1:45 PM.

Diff Detail

Event Timeline

steveire requested review of this revision.Jan 4 2021, 1:45 PM
steveire created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptJan 4 2021, 1:45 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
aaron.ballman added inline comments.Jan 5 2021, 9:34 AM
clang/lib/ASTMatchers/ASTMatchFinder.cpp
245

Should we be traversing the init statement before the loop variable so that the traversals happen in lexical order?

steveire added inline comments.Jan 5 2021, 9:52 AM
clang/lib/ASTMatchers/ASTMatchFinder.cpp
245

Do you mean that in

for (auto i : arr)
{
}

to visit the arr before the auto i?

I think visiting the auto i before the arr makes sense.

aaron.ballman added inline comments.Jan 5 2021, 9:59 AM
clang/lib/ASTMatchers/ASTMatchFinder.cpp
245

Nope, I mean that in:

for (int i = 12; auto j : {1, 2, 3, 4}) {}

we should visit the int i = 12; before the auto j

steveire updated this revision to Diff 314654.Jan 5 2021, 10:34 AM

Update

clang/lib/ASTMatchers/ASTMatchFinder.cpp
245

That was actually missing entirely. Added now.

aaron.ballman accepted this revision.Jan 5 2021, 12:29 PM

LGTM!

clang/lib/ASTMatchers/ASTMatchFinder.cpp
245

I thought getRangeInit() was doing that already, so nice!

This revision is now accepted and ready to land.Jan 5 2021, 12:29 PM
This revision was landed with ongoing or failed builds.Jan 5 2021, 1:31 PM
This revision was automatically updated to reflect the committed changes.