We encounter a few internal reports that we're dereference a nullptr.
Unfortunately, no small reproduce testcase for this crash yet, but it makes the
clangd more robost on broken code.
Differential Revision: https://reviews.llvm.org/D143486
Loc = getHighlightableSpellingToken(Loc, SourceMgr);
if (Loc.isInvalid())
return std::nullopt;
-
+ // We might have offsets in the main file that don't correspond to any
+ // spelled tokens.
const auto *Tok = TB.spelledTokenAt(Loc);
- assert(Tok);
-
+ if (!Tok)
+ return std::nullopt;
return halfOpenToRange(SourceMgr,
Tok->range(SourceMgr).toCharRange(SourceMgr));
}