[PATCH] D66590: [clangd] Fix toHalfOpenFileRange where start/end endpoints are in different files due to #include

Sam McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 22 07:06:32 PDT 2019


sammccall marked 4 inline comments as done.
sammccall added inline comments.


================
Comment at: clang-tools-extra/clangd/SourceCode.cpp:318
-// Check if two locations have the same file id.
-static bool inSameFile(SourceLocation Loc1, SourceLocation Loc2,
-                       const SourceManager &SM) {
----------------
I dropped this function because it's just SM.isSpelledInSameFile


================
Comment at: clang-tools-extra/clangd/SourceCode.cpp:338
+          : R2.getBegin();
+  SourceLocation End =
+      SM.isBeforeInTranslationUnit(getLocForTokenEnd(R1.getEnd(), SM, LangOpts),
----------------
this is an unrelated bug fix: E1 < E2, std::min() etc don't do anything sensible for SourceLocation


================
Comment at: clang-tools-extra/clangd/SourceCode.cpp:358
        Begin = Begin.isFileID()
-                   ? SourceLocation()
+                   ? includeHashLoc(SM.getFileID(Begin), SM)
                    : SM.getImmediateExpansionRange(Begin).getBegin()) {
----------------
This is half of the real fix: once we've hit the top of the macro tree, we should walk up the `#include` stack in case we find a common ancestor there.


================
Comment at: clang-tools-extra/clangd/SourceCode.cpp:443
+  SourceRange Result =
+      rangeInCommonFile(unionTokenRange(R1, R2, SM, LangOpts), SM, LangOpts);
   unsigned TokLen = getTokenLengthAtLoc(Result.getEnd(), SM, LangOpts);
----------------
this is one part of the main fix: the start and endpoint may be in different real files in the presence of #include


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D66590/new/

https://reviews.llvm.org/D66590





More information about the cfe-commits mailing list