[clang] [NFC] [clang] Use std::string instead of StringRef to reduce stack usage (PR #114285)

Chinmay Deshpande via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 30 13:13:17 PDT 2024


chinmaydd wrote:

Thank you everyone for the review.

On my local setup, this function occupies close to 185KB of local stack (MSVC 14.38.33130), which is really wasteful. Like @kparzysz highlighted, we observed a crash in `__chkstk()` which is inserted by MSVC in the prologue when a function requests for more than 8KB (on x64) of stack space for local variables. 

Another such function we observed was `TargetLibraryInfoImpl::addVectorizableFunctionsFromVecLib`. Its stack usage was fixed earlier this year (https://github.com/llvm/llvm-project/pull/86829).

MSVC does not provide a flag such as `-fstack-usage`, but I was able to perform some basic binary analysis to identify that close to 800 functions use more than 8KB of stack and around 14 use more than 64KB. I feel like in the longer term, we should look at reducing this since the clang driver may be invoked in-process with limited stack space available for the executing thread.

@erichkeane thanks for taking the time to suggest a clear way forward. I'll write a patch that attempts to achieve the same. I'll close this PR for now. 

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


More information about the cfe-commits mailing list