[clang] [clang-tools-extra] [clangd] Fix crash with null check for Token at Loc (PR #94528)
kadir çetinkaya via cfe-commits
cfe-commits at lists.llvm.org
Thu Jun 6 06:27:43 PDT 2024
================
@@ -387,8 +387,8 @@ const syntax::Token *TokenBuffer::spelledTokenAt(SourceLocation Loc) const {
assert(Loc.isFileID());
const auto *Tok = llvm::partition_point(
spelledTokens(SourceMgr->getFileID(Loc)),
- [&](const syntax::Token &Tok) { return Tok.location() < Loc; });
- if (!Tok || Tok->location() != Loc)
+ [&](const syntax::Token &Tok) { return Tok.endLocation() <= Loc; });
+ if (!Tok || Tok->location() > Loc || Loc >= Tok->endLocation())
----------------
kadircet wrote:
can you also update `clang/unittests/Tooling/Syntax/TokensTest.cpp` ?
https://github.com/llvm/llvm-project/pull/94528
More information about the cfe-commits
mailing list