From 7d71acf1bb1c034316f6d841e6ee6a91dee78452 Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Fri, 30 Jun 2023 18:42:37 -0600 Subject: [PATCH] AK: Use __builtin_frame_address to find current stack depth remaining Instead of checking the address of a temporary, grab the address of the current frame pointer to determine how much memory is left on the stack. This better communicates to the compiler what we're trying to do, and resolves some crashes with ASAN in test-js while the option detect_stack_use_after_return is turned on. --- AK/StackInfo.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/AK/StackInfo.h b/AK/StackInfo.h index 668bbd802f2..f741cd54561 100644 --- a/AK/StackInfo.h +++ b/AK/StackInfo.h @@ -19,8 +19,8 @@ public: size_t size() const { return m_size; } size_t size_free() const { - FlatPtr dummy; - return reinterpret_cast(&dummy) - m_base; + auto p = reinterpret_cast(__builtin_frame_address(0)); + return p - m_base; } private: