From efbfcd1de01b3a05fc0d1346a6bee35abaa7eb42 Mon Sep 17 00:00:00 2001 From: Demetrius Kanios Date: Tue, 14 Jul 2026 13:09:07 -0700 Subject: [PATCH] Fix `getStackTop` on LLVM older than 18. --- druntime/src/core/thread/osthread.d | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/druntime/src/core/thread/osthread.d b/druntime/src/core/thread/osthread.d index e84d869f02..075f215e60 100644 --- a/druntime/src/core/thread/osthread.d +++ b/druntime/src/core/thread/osthread.d @@ -1745,10 +1745,7 @@ in (fn) // // Spilling has to be done somehow else. - import ldc.intrinsics; - - static if (LLVM_atleast!22) sp = llvm_stackaddress(); - else sp = llvm_stacksave(); + sp = getStackTop(); } else version (FreeStanding) { assert(0); @@ -1864,7 +1861,22 @@ version (LDC) import ldc.intrinsics; static if (LLVM_atleast!22) return llvm_stackaddress(); - else return llvm_stacksave(); + else static if (LLVM_atleast!18) return llvm_stacksave(); + else { + // Inline assembly to workaround issue solved by + // https://github.com/llvm/llvm-project/pull/68133 + // + // Which wasn't merged/fixed until LLVM 18 + + import ldc.llvmasm; + + enum string isize = size_t.sizeof == 8 ? "i64" : "i32"; + return __asm!(void*)(` + .globaltype __stack_pointer, `~isize~` + global.get __stack_pointer + local.set $0 + `, "=r"); + } } } else