[Issue 18274] New: va_arg (TypeInfo) broken for static arrays
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Jan 21 15:27:53 UTC 2018
https://issues.dlang.org/show_bug.cgi?id=18274
Issue ID: 18274
Summary: va_arg (TypeInfo) broken for static arrays
Product: D
Version: D2
Hardware: x86_64
OS: Linux
Status: NEW
Severity: enhancement
Priority: P1
Component: druntime
Assignee: nobody at puremagic.com
Reporter: johannespfau at gmail.com
This code is currently broken:
https://run.dlang.io/is/68hf1w
---------------------------------------------
void foo(...)
{
uint[4] data;
va_arg(_argptr, _arguments[0], &data);
//data = va_arg!(uint[4])(_argptr);
writeln(data);
}
void main()
{
uint[4] value = [1, 2, 3, 4];
foo(value);
}
---------------------------------------------
[4, 0, 3567405808, 32767]
The commented, static variant works. The problem is that DMD passes static
arrays as {.ptr, .length} slice with TypeInfo_Tuple for D variadic functions.
va_arg would have to detect this and instead of just copying the data it has to
dereference the pointer. I'm not sure if this is easily possible though: DMD
passes TypeInfo_Tuple instead of TypeInfo_StaticArray. Can TypeInfo_Tuple only
occur for static arrays? If so, fixing this is easy. If not, we have to pass
proper TypeInfo for static array parameters.
I don't know why we even do this, at least on AArch64 we can have much better
performance by just passing static arrays by value in the same way a struct
would be passed. Passing as ptr+length requires another special case in the
va_arg function for static arrays.
--
More information about the Digitalmars-d-bugs
mailing list