Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Commit e56cd8f

Browse files
committed
core.stdc.stdarg: Little fix for Win64 and structs of sizes in [3,5-7] bytes
On Win64, structs of non-power-of-2 size are passed indirectly by value: https://docs.microsoft.com/en-us/cpp/build/x64-calling-convention?view=vs-2019#parameter-passing
1 parent fa0afa8 commit e56cd8f

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/core/stdc/stdarg.d

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,8 @@ void va_arg(T)(ref va_list ap, ref T parmn)
184184
}
185185
else version (Win64)
186186
{
187-
static if (T.sizeof > size_t.sizeof)
187+
// passed indirectly by value if > 64 bits or of a size that is not a power of 2
188+
static if (T.sizeof > size_t.sizeof || (T.sizeof & (T.sizeof - 1)) != 0)
188189
parmn = **cast(T**) ap;
189190
else
190191
parmn = *cast(T*) ap;
@@ -272,7 +273,7 @@ void va_arg()(ref va_list ap, TypeInfo ti, void* parmn)
272273
auto p = ap;
273274
auto tsize = ti.tsize;
274275
ap = cast(va_list) (p + size_t.sizeof);
275-
void* q = (tsize > size_t.sizeof) ? *cast(void**) p : p;
276+
void* q = (tsize > size_t.sizeof || (tsize & (tsize - 1)) != 0) ? *cast(void**) p : p;
276277
parmn[0..tsize] = q[0..tsize];
277278
}
278279
else version (SysV_x64)

0 commit comments

Comments
 (0)