[clang] [libclang/python] Fix bug in `SourceRange.__contains__`, add tests (PR #101802)

Vlad Serebrennikov via cfe-commits cfe-commits at lists.llvm.org
Sat Aug 10 05:47:37 PDT 2024


================
@@ -386,6 +386,10 @@ def __contains__(self, other):
         # same file, in between lines
         if self.start.line < other.line < self.end.line:
             return True
+        # between columns in one-liner range
+        elif self.start.line == other.line == self.end.line:
----------------
Endilll wrote:

> On C++ side, in SourceLocation.h we implement operator==, operator<= both as direct comparisons on the raw encoding (SourceLocation::getRawEncoding()). This is not file-sensitive.*

I believe raw encoding is file-sensitive.

If you say that `clang_equalLocations` is file-sensitive, then `SourceLocation::operator==` is file-sensitive, too. If you look at how `CXSourceLocation` are initialized, `int_data` is raw encoding, and `ptr_data[0]` is `SourceManager` (`ptr_data[1]` seems to be a dead weight).

https://github.com/llvm/llvm-project/pull/101802


More information about the cfe-commits mailing list