Skip to content

Commit 41a6085

Browse files
committed
[clangd] Fix a crash in semantic highlighting.
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
1 parent 4da2838 commit 41a6085

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

clang-tools-extra/clangd/SemanticHighlighting.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -519,10 +519,11 @@ class HighlightingsBuilder {
519519
Loc = getHighlightableSpellingToken(Loc, SourceMgr);
520520
if (Loc.isInvalid())
521521
return std::nullopt;
522-
522+
// We might have offsets in the main file that don't correspond to any
523+
// spelled tokens.
523524
const auto *Tok = TB.spelledTokenAt(Loc);
524-
assert(Tok);
525-
525+
if (!Tok)
526+
return std::nullopt;
526527
return halfOpenToRange(SourceMgr,
527528
Tok->range(SourceMgr).toCharRange(SourceMgr));
528529
}

0 commit comments

Comments
 (0)