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
Please rename this function to make it clearer what it's doing. The old implementation is the obvious one for a function with this name. Maybe isSpellingLocInFileRange or similar?