Bug 1543 – std.boxer broken for gdc (was: Incorrect passing of floats to variadic functions)
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Linux
Creation time
2007-10-01T18:20:00Z
Last change time
2015-06-09T05:14:47Z
Assigned to
dvdfrdmn
Creator
mariusmuja
Comments
Comment #0 by mariusmuja — 2007-10-01T18:20:58Z
The following program outputs 0 instead of the correct value (95):
import std.stdio;
import std.boxer;
void main(char[][] args)
{
float a = 95.0f;
Box b = box(a);
writefln(b);
}
I have tested it with the latest svn version of gdc and it doesn't work rorrectly. It outputs the correct value when compiled with dmd.
Comment #1 by mariusmuja — 2007-10-13T02:16:03Z
The error seems to be from the fact that gdc doesn't pass correctly float arguments to variadic functions. In the following example the function foo_d() prints the expected value, but the function foo() doesn't.
import std.stdio;
void foo(...)
{
writefln(*cast(float*)_argptr);
}
void foo_d( ...)
{
writefln(*cast(double*)_argptr);
}
void main()
{
foo(10.1f);
foo_d(10.1);
}
Comment #2 by afb — 2007-10-13T02:40:22Z
Seems to be working here, if you avoid the unportable casts...
import std.stdio;
import std.stdarg;
void foo(...)
{
writefln(va_arg!(float)(_argptr));
}
void foo_d( ...)
{
writefln(va_arg!(double)(_argptr));
}
void main()
{
foo(10.1f);
foo_d(10.1);
}
Comment #3 by mariusmuja — 2007-10-13T03:57:45Z
I didn't know about va_arg!()(). It seems then that std.boxer is broken for gdc, since it uses the unportable casts and assumes _argptr is of type void*, which by looking at std.stdarg it not necessarily true.
Comment #4 by afb — 2007-10-13T04:12:25Z
I think that's a known issue, since std.boxer says: "This module make not work on all GCC targets due to assumptions about the type of va_list."
Comment #5 by dvdfrdmn — 2007-10-13T16:46:49Z
Fixed this particular problem on targets for which std.boxer already works. Also fixed for 1- and 2-bit integral types. Fix is in SVN rev 183 / release 0.25.