This is an archive of the discontinued LLVM Phabricator instance.

[libTooling] Add flag to getRangeForEdit to ignore macro expansions
ClosedPublic

Authored by li.zhe.hua on Dec 8 2022, 2:55 PM.

Details

Summary

This commit resolves the FIXME around the behavior of
Lexer::makeFileCharRange that getRangeForEdit inherits around
source locations in macro expansions.

We add a flag to getRangeForEdit that allows a caller to disable the
behavior, and instead uses the spelling location instead, with checks
to ensure that the source locations are not within a macro definition.

Diff Detail

Event Timeline

li.zhe.hua created this revision.Dec 8 2022, 2:55 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 8 2022, 2:55 PM
li.zhe.hua requested review of this revision.Dec 8 2022, 2:55 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 8 2022, 2:55 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
ymandel accepted this revision.Dec 8 2022, 7:19 PM
ymandel added inline comments.
clang/lib/Tooling/Transformer/SourceCode.cpp
90–92

can you comment on the logic here? Why isn't this just "return true", since it's in a macro but not a part of a macro arg, I'd think it must be part of a macro definition.

111–113

LLVM style doesn't use braces for single-line ifs.

This revision is now accepted and ready to land.Dec 8 2022, 7:19 PM
li.zhe.hua updated this revision to Diff 481506.Dec 8 2022, 7:34 PM

Address comments

li.zhe.hua marked 2 inline comments as done.Dec 8 2022, 7:36 PM
li.zhe.hua added inline comments.
clang/lib/Tooling/Transformer/SourceCode.cpp
90–92

Good catch, it should just return true.

This revision was landed with ongoing or failed builds.Dec 8 2022, 7:41 PM
This revision was automatically updated to reflect the committed changes.
li.zhe.hua marked an inline comment as done.