From c2374b80c83dc498d16a21ad61595d9b1a381a8d Mon Sep 17 00:00:00 2001 From: Tzvetan Mikov Date: Fri, 1 Nov 2024 19:09:34 -0700 Subject: [PATCH] SctackBoundsTest.cpp: fix compilation error on Windows Summary: MSVC doesn't support __builtin_frame_address(), which breaks compilation. Technically, we don't have support for stack-checking on Windows at all, but at least we should be able to compile this test and it should just start working automatically when we do add support. Differential Revision: D65375190 --- unittests/Support/StackBoundsTest.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/unittests/Support/StackBoundsTest.cpp b/unittests/Support/StackBoundsTest.cpp index 3c1f2493038..4060ba0c0a0 100644 --- a/unittests/Support/StackBoundsTest.cpp +++ b/unittests/Support/StackBoundsTest.cpp @@ -32,7 +32,12 @@ bool isStackOverflowingSlowPath() { auto [highPtr, size] = oscompat::thread_stack_bounds(nativeStackGap); nativeStackHigh = (const char *)highPtr; nativeStackSize = size; +#ifdef __GNUC__ void *sp = __builtin_frame_address(0); +#else + volatile char *var = 0; + void *sp = (void *)&var; +#endif return (uintptr_t)nativeStackHigh - (uintptr_t)sp > nativeStackSize; } @@ -40,7 +45,12 @@ bool isStackOverflowingSlowPath() { /// current thread. Updates the stack bounds if the thread which Runtime /// is executing on changes. inline bool isOverflowing() { +#ifdef __GNUC__ void *sp = __builtin_frame_address(0); +#else + volatile char *var = 0; + void *sp = (void *)&var; +#endif // Check for overflow by subtracting the sp from the high pointer. // If the sp is outside the valid stack range, the difference will // be greater than the known stack size. @@ -118,6 +128,8 @@ TEST(StackBoundsTest, unboundRecursion_thread) { } #if !defined(_WINDOWS) && !defined(__EMSCRIPTEN__) +// Windows/EMSCRIPTEN don't support pthreads well. + void runInThreadWith64KGuard(void *(threadFunc)(void *)) { pthread_t thread; pthread_attr_t attr;