[clang] [clang-format] Limit how much work guessLanguage() can do (PR #78925)

Owen Pan via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 20 00:45:51 PST 2024


owenca wrote:

> > couldn't we just use the .clang-format-ignore file to say... hey don't bother with this file, we can't do it...
> 
> I think that's a good solution for avoiding the OOM when actually trying to format the file, in combination with this patch for avoiding the OOM in `guessLanguage()`.
> 
> The reason this is such a severe issue for clangd is that clangd calls into `guessLanguage()` whenever a file is opened, thereby triggering the OOM for any downstream user of such a single-header library who happens to open the header in their editor, not just developers of the library itself. Those users have no reason to try to format the library header, so this would solve what's otherwise a puzzling hang for them with no configuration required.

The OOM is not limited to `guessLanguage()`. (See 119a72866f0e for an improvement to the performance of `guessLanguage()`.) It occurs even if you rename the header files to .cpp files and clang-format the renamed files directly. I'm with @mydeveloperday on this and believe a more general solution is needed.

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


More information about the cfe-commits mailing list