[PATCH] D65574: Added hack to prevent toHalfOpenFileRange assertion fail

Shaurya Gupta via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 1 06:34:37 PDT 2019


SureYeaah created this revision.
SureYeaah added reviewers: sammccall, kadircet.
Herald added subscribers: cfe-commits, arphaman, jkorous, ilya-biryukov.
Herald added a project: clang.

- Still need to investigate why this is happening.
- Fixes the crash described at https://github.com/clangd/clangd/issues/113


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D65574

Files:
  clang-tools-extra/clangd/Selection.cpp
  clang-tools-extra/clangd/SourceCode.cpp


Index: clang-tools-extra/clangd/SourceCode.cpp
===================================================================
--- clang-tools-extra/clangd/SourceCode.cpp
+++ clang-tools-extra/clangd/SourceCode.cpp
@@ -311,8 +311,11 @@
                                      const LangOptions &LangOpts) {
   SourceRange FileRange = Loc;
   while (!FileRange.getBegin().isFileID()) {
-    assert(!FileRange.getEnd().isFileID() &&
-           "Both Begin and End should be MacroIDs.");
+    // FIXME: Investigate when this assert fails. Added a hack until then.
+    // assert(!FileRange.getEnd().isFileID() &&
+    //       "Both Begin and End should be MacroIDs.");
+    if(FileRange.getEnd().isFileID())
+      return SourceRange();
     if (SM.isMacroArgExpansion(FileRange.getBegin())) {
       FileRange.setBegin(SM.getImmediateSpellingLoc(FileRange.getBegin()));
       FileRange.setEnd(SM.getImmediateSpellingLoc(FileRange.getEnd()));
Index: clang-tools-extra/clangd/Selection.cpp
===================================================================
--- clang-tools-extra/clangd/Selection.cpp
+++ clang-tools-extra/clangd/Selection.cpp
@@ -369,7 +369,8 @@
     //   }
     // Selecting "++x" or "x" will do the right thing.
     auto Range = toHalfOpenFileRange(SM, LangOpts, S);
-    assert(Range && "We should be able to get the File Range");
+    if(!Range)
+      return SelectionTree::Unselected;
     dlog("{1}claimRange: {0}", Range->printToString(SM), indent());
     auto B = SM.getDecomposedLoc(Range->getBegin());
     auto E = SM.getDecomposedLoc(Range->getEnd());


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D65574.212799.patch
Type: text/x-patch
Size: 1570 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190801/968b1b7c/attachment.bin>


More information about the cfe-commits mailing list