From d0c973a7a0149db3b71767d4c5a20a31e6a8ed5b Mon Sep 17 00:00:00 2001 From: Michael Spencer Date: Tue, 15 Apr 2025 11:19:07 -0700 Subject: [llvm][clang] Allocate a new stack instead of spawning a new thread to get more stack space (#133173) Clang spawns a new thread to avoid running out of stack space. This can make debugging and performance analysis more difficult as how the threads are connected is difficult to recover. This patch introduces `runOnNewStack` and applies it in Clang. On platforms that have good support for it this allocates a new stack and moves to it using assembly. Doing split stacks like this actually runs on most platforms, but many debuggers and unwinders reject the large or backwards stack offsets that occur. Apple platforms and tools are known to support this, so this only enables it there for now. --- clang/lib/Frontend/CompilerInstance.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'clang/lib/Frontend/CompilerInstance.cpp') diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index 243e0a3..5fe80fc 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -1265,7 +1265,7 @@ bool CompilerInstance::compileModule(SourceLocation ImportLoc, // Execute the action to actually build the module in-place. Use a separate // thread so that we get a stack large enough. - bool Crashed = !llvm::CrashRecoveryContext().RunSafelyOnThread( + bool Crashed = !llvm::CrashRecoveryContext().RunSafelyOnNewStack( [&]() { GenerateModuleFromModuleMapAction Action; Instance.ExecuteAction(Action); -- cgit v1.1