Skip to content
This repository was archived by the owner on Feb 8, 2024. It is now read-only.

Commit c33fc00

Browse files
committed
ARM AAPCS stdarg/vararg alignment
Types with natural alignment >= 8-bytes (e.g. double) will be 8-byte aligned instead of usual 4-byte alignment.
1 parent 013841f commit c33fc00

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

src/core/stdc/stdarg.d

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ module core.stdc.stdarg;
1818
version ( PPC ) version = AnyPPC;
1919
version ( PPC64 ) version = AnyPPC;
2020

21+
version( ARM )
22+
{
23+
// iOS, tvOS use older APCS variant instead of AAPCS
24+
version( iOS ) {}
25+
else version( TVOS ) {}
26+
else version = AAPCS;
27+
}
28+
2129
version( X86_64 )
2230
{
2331
// Determine if type is a vector type
@@ -287,8 +295,6 @@ version( X86_64 )
287295

288296
version( LDC )
289297
{
290-
// FIXME: This isn't actually tested at all for ARM.
291-
292298
version( X86_64 )
293299
{
294300
version( Win64 ) {}
@@ -357,6 +363,13 @@ version( LDC )
357363
}
358364
else version( ARM )
359365
{
366+
// AAPCS sec 5.5 B.5: type with alignment >= 8 is 8-byte aligned
367+
// instead of normal 4-byte alignment (APCS doesn't do this).
368+
version( AAPCS )
369+
{
370+
if (T.alignof >= 8)
371+
ap = cast(va_list)((cast(size_t)ap + 7) & ~7);
372+
}
360373
T arg = *cast(T*)ap;
361374
ap += (T.sizeof + size_t.sizeof - 1) & ~(size_t.sizeof - 1);
362375
return arg;
@@ -407,6 +420,13 @@ version( LDC )
407420
}
408421
else version( ARM )
409422
{
423+
// AAPCS sec 5.5 B.5: type with alignment >= 8 is 8-byte aligned
424+
// instead of normal 4-byte alignment (APCS doesn't do this).
425+
version( AAPCS )
426+
{
427+
if (T.alignof >= 8)
428+
ap = cast(va_list)((cast(size_t)ap + 7) & ~7);
429+
}
410430
parmn = *cast(T*)ap;
411431
ap += (T.sizeof + size_t.sizeof - 1) & ~(size_t.sizeof - 1);
412432
}
@@ -449,9 +469,13 @@ version( LDC )
449469
}
450470
else version( ARM )
451471
{
452-
// Wait until everyone updates to get TypeInfo.talign
453-
//auto talign = ti.talign;
454-
//auto p = cast(va_list) ((cast(size_t)ap + talign - 1) & ~(talign - 1));
472+
// AAPCS sec 5.5 B.5: type with alignment >= 8 is 8-byte aligned
473+
// instead of normal 4-byte alignment (APCS doesn't do this).
474+
version( AAPCS )
475+
{
476+
if (ti.talign >= 8)
477+
ap = cast(va_list)((cast(size_t)ap + 7) & ~7);
478+
}
455479
auto p = ap;
456480
ap = p + ((tsize + size_t.sizeof - 1) & ~(size_t.sizeof - 1));
457481
}

0 commit comments

Comments
 (0)