[PATCH] D50740: [SourceManager] isPointWithin: avoid using isBeforeInTranslationUnit, compare buffer offsets directly for lexical correctness
Alex Lorenz via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 14 14:56:23 PDT 2018
arphaman created this revision.
arphaman added reviewers: jkorous, klimek, ioeric, vsapsai, ilya-biryukov.
Herald added a subscriber: dexonsmith.
The current implementation of `isPointWithin` uses `isBeforeInTranslationUnit` to check if a location is within a range.
The problem is that `isPointWithin` is used to perform is lexical range check, i.e. we want to determine if a location in a particular source file is within a source range in the same source file.
The use of `isBeforeInTranslationUnit` is not correct for this use-case, as one source file can be included multiple times. Given a source range and a location that's lexically contained within that source range (e.g. file.h:1:2->1:10 and file:h:1:5), `isBeforeInTranslationUnit` will fail to correctly determine if a source range from the first occurrence of the source file contains a location from the second occurrence of the same source file, as the start and end of the range are both included before the location.
This patch reimplements `isPointWithin` to ensure that buffer offsets are compared directly for lexical correctness.
This patch is a pre-requisuite to fix a bug in clang-rename where we are unable to rename a structure in a PCH that has a header that's included multiple times (follow-up patch will be posted to update clang-rename to use isPointWithin).
rdar://42746284
Repository:
rC Clang
https://reviews.llvm.org/D50740
Files:
include/clang/Basic/SourceManager.h
lib/Basic/SourceManager.cpp
unittests/Basic/SourceManagerTest.cpp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D50740.160696.patch
Type: text/x-patch
Size: 5608 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180814/bc4b7f32/attachment.bin>
More information about the cfe-commits
mailing list