Skip to content

Commit 7c3fadc

Browse files
committed
fix alignment on C interop in x86_64 backend
1 parent 019a2b0 commit 7c3fadc

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

source/backends/x86_64.d

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,17 @@ class BackendX86_64 : CompilerBackend {
515515
output ~= "mov rbp, rsp\n";
516516
output ~= "and rsp, 0xFFFFFFFFFFFFFFF0\n";
517517

518+
size_t alignSize = word.params.length * 8;
519+
520+
while (alignSize % 16 != 0) {
521+
alignSize += 8;
522+
}
523+
alignSize -= word.params.length * 8;
524+
525+
if (alignSize > 0) {
526+
output ~= format("sub rsp, %d\n", alignSize);
527+
}
528+
518529
if (word.params.length > 6) {
519530
// push parameters
520531
foreach_reverse (i ; 6 .. word.params.length) {

0 commit comments

Comments
 (0)