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());


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());
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to