Bug 22621 – [REG2.094] static real array not passed correctly to function as r-value

Status
NEW
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2021-12-22T20:52:15Z
Last change time
2024-12-13T19:20:05Z
Keywords
wrong-code
Assigned to
No Owner
Creator
Tony Edgin
Moved to GitHub: dmd#20029 →

Comments

Comment #0 by tedgin — 2021-12-22T20:52:15Z
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 [email protected](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.
Comment #1 by ryuukk.dev — 2021-12-22T21:26:20Z
sounds like it is similar to my issue: https://issues.dlang.org/show_bug.cgi?id=22583
Comment #2 by ag0aep6g — 2021-12-23T06:26:10Z
Works correctly with 2.093. Fails since 2.094.
Comment #3 by robert.schadek — 2024-12-13T19:20:05Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/20029 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB