Bug 20771 – va_arg doesn't work for structs with postblits

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-04-26T14:42:26Z
Last change time
2020-04-27T03:27:59Z
Keywords
pull
Assigned to
No Owner
Creator
Iain Buclaw

Comments

Comment #0 by ibuclaw — 2020-04-26T14:42:26Z
This prints: Postblit = 0:2:153259628: ``` void testVariadic(T)(int nargs, ...) { printf(T.stringof ~ "= "); foreach(i; 0 .. nargs) { auto arg = va_arg!T(_argptr); static if (__traits(compiles, arg.value)) printf("%d", arg.value); //assert(arg.value == i); else assert(arg == T.init); printf(":"); } printf("\n"); } struct Postblit { int value; this(this) nothrow { } // nothrow ? } void test2() { auto a0 = Postblit(0); auto a1 = Postblit(1); auto a2 = Postblit(2); testVariadic!Postblit(3, a0, a1, a2); } ```
Comment #1 by ibuclaw — 2020-04-26T14:59:48Z
I don't think this is a druntime bug. The compiler sets __argTypes differently for structs with postblits vs. structs without: ``` static if (is(T U == __argTypes)) pragma(msg, T, " = ", U); ``` Prints: Postblit = () NoPostblit = (int)
Comment #2 by kinke — 2020-04-26T17:24:29Z
(In reply to Iain Buclaw from comment #1) > The compiler sets __argTypes differently for structs with postblits vs. structs without Which is correct, as only PODs are passed in registers, so an empty argTypes tuple for non-PODs is fine. DMD passes non-PODs on the stack; C++ and LDC pass them indirectly by value (pointer to caller-allocated copy). The current SysV va_arg implementation in druntime assumes DMD's ABI in this regard.
Comment #3 by dlang-bot — 2020-04-26T22:44:43Z
@ibuclaw created dlang/dmd pull request #11065 "fix Issue 20771, 20772, disallow passing non-trivially copyable types as variadic arguments" fixing this issue: - fix Issue 20771 - va_arg doesn't work for structs with postblits https://github.com/dlang/dmd/pull/11065
Comment #4 by dlang-bot — 2020-04-27T03:27:59Z
dlang/dmd pull request #11065 "fix Issue 20771, 20772, 20775 disallow passing non-trivially copyable types as variadic arguments" was merged into master: - a7a9b09bf71cf194ae431fc7d4e3f37147bef6ac by Iain Buclaw: fix Issue 20771 - va_arg doesn't work for structs with postblits https://github.com/dlang/dmd/pull/11065