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

Commit 73e1f93

Browse files
committed
core.stdc.stdarg: Upstream LDC special case for Win64
I think that's the last one.
1 parent e56cd8f commit 73e1f93

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

src/core/stdc/stdarg.d

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,18 @@ void va_arg(T)(ref va_list ap, ref T parmn)
184184
}
185185
else version (Win64)
186186
{
187+
// LDC passes slices as 2 separate 64-bit values, not as 128-bit struct
188+
version (LDC) enum isLDC = true;
189+
else enum isLDC = false;
190+
static if (isLDC && is(T == E[], E))
191+
{
192+
const length = *cast(size_t*) ap;
193+
ap += size_t.sizeof;
194+
auto ptr = *cast(typeof(parmn.ptr)*) ap;
195+
parmn = ptr[0 .. length];
196+
}
187197
// 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)
198+
else static if (T.sizeof > size_t.sizeof || (T.sizeof & (T.sizeof - 1)) != 0)
189199
parmn = **cast(T**) ap;
190200
else
191201
parmn = *cast(T*) ap;
@@ -267,13 +277,25 @@ void va_arg()(ref va_list ap, TypeInfo ti, void* parmn)
267277
}
268278
else version (Win64)
269279
{
280+
version (LDC) enum isLDC = true;
281+
else enum isLDC = false;
282+
270283
// Wait until everyone updates to get TypeInfo.talign
271284
//auto talign = ti.talign;
272285
//auto p = cast(void*)(cast(size_t)ap + talign - 1) & ~(talign - 1);
273286
auto p = ap;
274287
auto tsize = ti.tsize;
275-
ap = cast(va_list) (p + size_t.sizeof);
276-
void* q = (tsize > size_t.sizeof || (tsize & (tsize - 1)) != 0) ? *cast(void**) p : p;
288+
void* q;
289+
if (isLDC && tsize == 16 && cast(TypeInfo_Array) ti)
290+
{
291+
q = p;
292+
ap = cast(va_list) (p + tsize);
293+
}
294+
else
295+
{
296+
q = (tsize > size_t.sizeof || (tsize & (tsize - 1)) != 0) ? *cast(void**) p : p;
297+
ap = cast(va_list) (p + size_t.sizeof);
298+
}
277299
parmn[0..tsize] = q[0..tsize];
278300
}
279301
else version (SysV_x64)

0 commit comments

Comments
 (0)