[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
Fri Jun 7 00:39:43 PDT 2024
================
@@ -447,7 +447,7 @@ class HighlightingsBuilder {
if (!RLoc.isValid())
return;
- const auto *RTok = TB.spelledTokenAt(RLoc);
+ const auto *RTok = TB.spelledTokenContaining(RLoc);
----------------
kadircet wrote:
so looks like this call site was actually expecting it to be null when provided with an offset into the token, but that's OK overall, as it's also trying to just slice the token.
can you update the surroundings to reflect the new behavior so we don't leave old state documented for future travelers? something like:
```
// RLoc is either part of `>>` or a spelled token on its own `>`.
// If it's the former, slice to have length of 1, if latter use the token as-is.
assert(RTok);
if (RTok->kind() == ...)
```
https://github.com/llvm/llvm-project/pull/94528
More information about the cfe-commits
mailing list