diff --git a/clang-tools-extra/clangd/SemanticHighlighting.cpp b/clang-tools-extra/clangd/SemanticHighlighting.cpp index e3022ad131ff2f..19f79f793420dc 100644 --- a/clang-tools-extra/clangd/SemanticHighlighting.cpp +++ b/clang-tools-extra/clangd/SemanticHighlighting.cpp @@ -519,10 +519,11 @@ class HighlightingsBuilder { 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)); }