Skip to content

Commit

Permalink
fix alignment on C interop in x86_64 backend
Browse files Browse the repository at this point in the history
  • Loading branch information
yeti0904 committed Nov 22, 2024
1 parent 019a2b0 commit 7c3fadc
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions source/backends/x86_64.d
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 7c3fadc

Please sign in to comment.