[cfe-dev] [clangd] Worker threads stack size

Dmitry.Kozhevnikov@jetbrains.com via cfe-dev cfe-dev at lists.llvm.org
Fri Aug 17 05:41:01 PDT 2018


Hello!

clangd uses std::thread for spawning worker threads to parse files (see AsyncTaskRunner::runAsync in tools/clang/tools/extra/clangd/Threading.cpp). Unfortunately, std::thread lacks the ability to customize the stack size, and the default one might be insufficient for parsing complex source files. For example, on macOS, the default stack size for non-main threads is 512K, so the following code causes a stack overflow (on my machine) with clangd, while being way below the default constexpr evaluation depth threshold:

	constexpr int foo(int x) {
	    return x == 1 ? 1 : foo(x - 1) + 1;
	}
	static_assert(foo(50) > 0, "");

This also can be observed on some real-world projects.

Do I understand correctly that the only way to fix it would be to abandon std::thread and reimplement the platform-specific thread spawning (using pthreads/WinAPI), or is there another solution available in LLVM/clang codebase?

Best regards,
Dmitry Kozhevnikov.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2861 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20180817/01d213b5/attachment.bin>


More information about the cfe-dev mailing list