digitalmars.D.bugs - [Issue 22621] New: static real array not passed correctly to
- d-bugmail puremagic.com (51/51) Dec 22 2021 https://issues.dlang.org/show_bug.cgi?id=22621
https://issues.dlang.org/show_bug.cgi?id=22621 Issue ID: 22621 Summary: static real array not passed correctly to function as r-value Product: D Version: D2 Hardware: x86_64 OS: Linux Status: NEW Severity: normal Priority: P1 Component: dmd Assignee: nobody puremagic.com Reporter: tedgin cyverse.org A static array of reals passed to a function as an r-value may have an incorrect value inside the function. The correctness depends on what is defined before the array in the caller's stack frame. Here's an example. ``` // bug.d import std.stdio; void f(real[1] x) do { writefln("x[0] = %e", x[0]); assert(x[0] == 2.0L, "x[0] != 2"); } void main() do { version (succeeds) { int _ = 1; } else { double _ = 1.0; } real[1] y = [ 2.0L ]; f(y); } ``` If an int is defined prior to the array, the program works as expected, but if a double is defined, the program fails. ``` ? rdmd -version=succeeds bug.d x[0] = 2.000000e+00 ? rdmd -version=fails bug.d x[0] = -4.344603e-713 core.exception.AssertError bug.d(8): x[0] != 2 ---------------- ??:? _d_assert_msg [0x55558abc29e4] ??:? void bug.f(real[1]) [0x55558ab95921] ??:? _Dmain [0x55558ab9596b] ``` I'm using dmd version 2.098.0 and rdmd build 20211010. --
Dec 22 2021