[clang-tools-extra] [clangd] Implement simple folding for preprocessor branches (PR #140959)

Nathan Ridge via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 23 05:33:48 PDT 2025


https://github.com/HighCommander4 requested changes to this pull request.

Thanks for adding some unit tests, and sorry I didn't get a chance to look at this sooner.

Unfortunately, it looks like the patch needs a bit more work, as I'm seeing it crash on incomplete code, for example:

```c++
#ifdef WALDO

#
```

This crashes, at least on an assertions-enabled build, with:

> include/llvm/ADT/ArrayRef.h:454: T &llvm::MutableArrayRef<clang::clangd::Token>::operator[](size_t) const [T = clang::clangd::Token]: Assertion `Index < this->size() && "Invalid index!"' failed.

That will need to be investigated and fixed before this patch can land. (Note that operations like folding ranges need to be robust and not crash on invalid code, especially on invalid code that is a plausible intermediate product of writing valid code, as in the above example, because the editor can potentially ask clangd to compute folding ranges after every keystroke.)

(As part of fixing this assertion failure, please include a unit test for the crashing testcase as well.)

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


More information about the cfe-commits mailing list