From 7c3fadc1496d4b9ebb2668d300bc7cb9be11b459 Mon Sep 17 00:00:00 2001 From: MESYETI Date: Fri, 22 Nov 2024 14:08:55 +0000 Subject: [PATCH] fix alignment on C interop in x86_64 backend --- source/backends/x86_64.d | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/source/backends/x86_64.d b/source/backends/x86_64.d index bf36615..2e4f578 100644 --- a/source/backends/x86_64.d +++ b/source/backends/x86_64.d @@ -515,6 +515,17 @@ class BackendX86_64 : CompilerBackend { output ~= "mov rbp, rsp\n"; output ~= "and rsp, 0xFFFFFFFFFFFFFFF0\n"; + size_t alignSize = word.params.length * 8; + + while (alignSize % 16 != 0) { + alignSize += 8; + } + alignSize -= word.params.length * 8; + + if (alignSize > 0) { + output ~= format("sub rsp, %d\n", alignSize); + } + if (word.params.length > 6) { // push parameters foreach_reverse (i ; 6 .. word.params.length) {