[clang-tools-extra] [clangd] Fix crash on completion with out-of-range position (PR #196112)

Aleksandr Platonov via cfe-commits cfe-commits at lists.llvm.org
Wed May 6 10:29:19 PDT 2026


ArcsinX wrote:

> It does get printed later at E level (we let it get re-checked
> 
> https://github.com/llvm/llvm-project/blob/0e6d57648584c3895abd3021fb8fa2a767146d5a/clang-tools-extra/clangd/CodeComplete.cpp#L2307-L2311
> 
> )
> Here's the output of the patched version when this issue is triggered:
> 
> ```
> I[17:38:38.534] <-- textDocument/completion(1)
> V[17:38:38.534] could not convert position '97:0' to offset for file '/tmp/test.cpp'
> E[17:38:38.534] Code completion position was invalid Line value is out of range (97)
> I[17:38:38.534] --> reply:textDocument/completion(1) 0 ms
> ```

Oh, got it.
I haven't looked at this in detail, but does it make sense to return true in shouldRunCompletion() if the offset is incorrect? If we return `false` in `shouldRunCompletion()`, we can return an empty result for completion earlier. But in that case, the `vlog` will have to be replaced with `elog`.

https://github.com/llvm/llvm-project/pull/196112


More information about the cfe-commits mailing list