Bug 24163 – Floating-point variadic array bug

Status
NEW
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Windows
Creation time
2023-09-26T07:08:23Z
Last change time
2024-12-13T19:30:58Z
Assigned to
No Owner
Creator
evilrat666
Moved to GitHub: dmd#18188 →

Comments

Comment #0 by evilrat666 — 2023-09-26T07:08:23Z
Here is a "funny" bug with variadic function taking float arguments, whenever foo takes the float parameter and Vector2 is a larger type then the second assert fails. It works as expected when foo and Vector2 is both float or double, or foo is not float. There is a strange behavior in the foo as well. Note that this only happens with DMD, with LDC it works correctly. This code is tested on Windows. Reproduction code ------------------------------ alias real_t = double; struct Vector2 { real_t x, y; this(real_t x, real_t y) { this.x = x; this.y = y; } } Vector2 foo(size_t nArgCount)(float[nArgCount] args...) { //import std.stdio; //writeln(args); // [0.5] //writeln(args[0]); // 0 //assert(args[0] == 0.5f); // assert failed return Vector2(args[0], args[0]); } void main() { // ok auto c = foo(0.5, 0.5); assert(c.x == 0.5 && c.y == 0.5); // Note that it is just by coincidence that the stack is zeroed, // in real program there will be garbage values. // This bug happens ONLY when foo type is float and Vector2 any other type. // It works properly with LDC, but not with DMD. import std.stdio; c = foo(0.5); writefln("%f, %f", c.x, c.y); // 0.000000, 0.000000 assert(c.x == 0.5 && c.y == 0.5); }
Comment #1 by robert.schadek — 2024-12-13T19:30:58Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18188 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB