Bug 13769 – Wrong argument passing for variadic functions in 64 bits
Status
RESOLVED
Resolution
WORKSFORME
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
All
Creation time
2014-11-23T14:36:00Z
Last change time
2020-08-31T10:28:53Z
Keywords
backend, wrong-code
Assigned to
No Owner
Creator
Mathias LANG
Comments
Comment #0 by pro.mathias.lang — 2014-11-23T14:36:00Z
The following code:
````
private unittest {
import core.vararg, std.stdio;
void fix() {}
void test_bug(size_t bug, ...) { assert(bug == size_t.max); }
void test_fixed(size_t bug, ...) { fix(); assert(bug == size_t.max); }
void print_bug(size_t bug, ...) { writeln(bug); assert(bug == size_t.max); }
void print_fix(size_t bug, ...) { fix(); writeln(bug); assert(bug == size_t.max); }
print_bug(size_t.max);
print_fix(size_t.max);
test_fixed(size_t.max);
test_bug(size_t.max);
}
````
Will trigger an unittest when put any Phobos module (for simplicity, I tested std.algorithm).
Example:
````
make[1]: Leaving directory '/mnt/shared/projects/dlang/druntime'
140734760252720
18446744073709551615
****** FAIL std.algorithm
core.exception.AssertError@std/algorithm.d(417): Assertion failure
----------------
generated/linux/release/64/unittest/libphobos2-ut.so(+0x28fb8e1) [0x7f2bf2fcd8e1]
````
As you see, the parameters passed during the first function call inside that function are wrong. I only appears with 64 bits parameters (including string).
I couldn't find any stand-alone snippet that reproduce the error. My guess is that it might originate from the way it's tested (shared library), but I currently lack the time to investigate further.
The issue was originally found in https://github.com/D-Programming-Language/phobos/pull/2677
This also outline the fact that variadic functions are poorly tested in Phobos.