This is an archive of the discontinued LLVM Phabricator instance.

[NFC] Extract method to SourceManager for traversing the macro "stack"
ClosedPublic

Authored by george.karpenkov on Jan 23 2018, 6:59 PM.

Details

Summary

The code for going up the macro arg expansion is duplicated in many places (and we need it for the analyzer as well, so I did not want to duplicate it two more times).

This patch is an NFC, so the semantics should remain the same.
I am still slightly confused as to why in half of the places getImmediateSpellingLoc is used, and getImmediateExpansionRange is used in the other half.

Diff Detail

Repository
rL LLVM

Event Timeline

george.karpenkov created this revision.
NoQ accepted this revision.Jan 26 2018, 3:23 PM

The change looks obviously correct, but it might need attention of someone who knows more than me about the SourceManager :)

This revision is now accepted and ready to land.Jan 26 2018, 3:23 PM
vsk added a subscriber: vsk.Jan 26 2018, 3:33 PM
vsk added inline comments.
lib/Sema/SemaChecking.cpp
9351 ↗(On Diff #131187)

Does getImmediateMacroCallerLoc differ at all from getImmediateSpellingLoc?

lib/Sema/SemaChecking.cpp
9351 ↗(On Diff #131187)

@vsk the former is called in a loop, if that is your question?..

vsk added inline comments.Feb 2 2018, 1:44 PM
lib/Sema/SemaChecking.cpp
9351 ↗(On Diff #131187)

No, you're replacing a loop which does:

while (...) L = getImmediateMacroCallerLoc(L);

with a loop that does:

while (...) L = getImmediateSpellingLoc(L);

Given that the precondition is that L is a macro arg expansion, I think the two loops are semantically equivalent, but I haven't dug into it much. I was just asking if you thought the same.

vsk accepted this revision.Feb 2 2018, 1:47 PM

Thanks!

lib/Sema/SemaChecking.cpp
9351 ↗(On Diff #131187)

Yeah I just double-checked, they are equivalent.

lib/Sema/SemaChecking.cpp
9351 ↗(On Diff #131187)

@vsk right, then it probably makes more sense to call getImmediateMacroCallerLoc

This revision was automatically updated to reflect the committed changes.
This revision was automatically updated to reflect the committed changes.