Bug 19662 – x86_64: Different code output when compiling with inline/boundscheck on/off

Status
REOPENED
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Windows
Creation time
2019-02-08T21:22:03Z
Last change time
2024-12-13T19:02:21Z
Keywords
backend, pull, wrong-code
Assigned to
No Owner
Creator
skocznymr
Moved to GitHub: dmd#19537 →

Comments

Comment #0 by skocznymr — 2019-02-08T21:22:03Z
The code below has different output depending on compilation options. Reproduced on Windows 10, DMD version v2.084.1-beta.1-master-1f85d7f, 64bit compilation. Doesn't occur when compiling to 32bit. Code partially lifted from dlib package. import std.stdio; import std.math; class Foo { Quaternion!float rotation; } class ObjHolder { Object[int] objs; } struct Quaternion(T) { Vector!(T,4) vectorof; alias vectorof this; Vector!() opBinaryRight() () { } static Quaternion!(T) fromEulerAngles(Vector!(T,3) e) { Quaternion!(T) q; T sr = sin(e.x ); q.w = sr; q.x = sr; q.y = sr; return q; } } struct Vector(T, int size) { static elements(string[] letters) { string res; foreach (i; 0..size) res ~= "T " ~ letters[i] ~ "; "; return res; } union { struct { mixin(elements(["x", "y", "z", "w"])); } } } alias Vector3f = Vector!(float, 3); void main() { ObjHolder oh = new ObjHolder; Object o = new Object; oh.objs[0] = o; writeln(oh.objs); Foo f = new Foo; f.rotation = Quaternion!float.fromEulerAngles(Vector3f()); } >dmd app.d -m64 >app [0:object.Object] <- good >dmd -inline app.d -m64 >app [0:object.Object] <- good >dmd -O -release app.d -m64 >app [0:object.Object] <- good >dmd -O -release -inline app.d -m64 >app [0:null] <- bad >dmd -O -release -inline -boundscheck=on app.d -m64 >app [0:object.Object] <- good >dmd -O -release -inline -boundscheck=off app.d -m64 >app [0:null] <- bad
Comment #1 by skocznymr — 2019-02-08T22:43:41Z
Further reduced version: import std.stdio; import std.math; class ObjHolder { Quaternion rotation; Object[int] objs; } struct Quaternion { float x, y, z, w; static Quaternion fromEulerAngles() { Quaternion q; float sr = sin(1.0f); q.w = sr; q.x = sr; q.y = sr; return q; } } void main() { ObjHolder oh = new ObjHolder; Object o = new Object; oh.objs[0] = o; writeln(oh.objs[0]); oh.rotation = Quaternion.fromEulerAngles(); } good output should be "Object.Object" bad output is "null"
Comment #2 by bugzilla — 2020-09-07T03:01:53Z
Tested HEAD on Linux64 and Windows64. Works for me.
Comment #3 by greeenify — 2020-09-07T03:57:50Z
Let's still add it to the testsuite: https://github.com/dlang/dmd/pull/11702
Comment #4 by moonlightsentinel — 2020-09-08T20:27:38Z
The test still fails on current master (e6a018e22e3040ef0051ab8fe42dc15e1df92019). Slightly modified test without Phobos and manual output verification: ========================================================= import core.math : sin; class ObjHolder { Quaternion rotation; Object[int] objs; } struct Quaternion { float x, y, z, w; static Quaternion fromEulerAngles() { Quaternion q; float sr = sin(1.0f); q.w = sr; q.x = sr; q.y = sr; return q; } } ObjHolder create() { ObjHolder oh = new ObjHolder; Object o = new Object; oh.objs[0] = o; oh.rotation = Quaternion.fromEulerAngles(); return oh; } void main() { ObjHolder oh = create(); if (!oh.objs[0]) assert(false); } =========================================================== > .\generated\windows\debug\64\dmd.exe -m64 -O -release -inline app.d > .\app.exe > echo $LASTEXITCODE -1073741795
Comment #5 by dlang-bot — 2020-11-10T09:20:45Z
@WalterBright created dlang/dmd pull request #11944 "fix Issue 19662 - x86_64: Different code output when compiling with i…" fixing this issue: - fix Issue 19662 - x86_64: Different code output when compiling with inline/boundscheck on/off https://github.com/dlang/dmd/pull/11944
Comment #6 by dlang-bot — 2022-07-18T09:00:21Z
dlang/dmd pull request #11944 "fix Issue 19662 - x86_64: Different code output when compiling with i…" was merged into master: - 45a3c0122a870f432d6818afb39aec2004204f7d by Walter Bright: fix Issue 19662 - x86_64: Different code output when compiling with inline/boundscheck on/off https://github.com/dlang/dmd/pull/11944
Comment #7 by ibuclaw — 2022-09-05T19:17:16Z
Not fixed. Test wasn't being ran in the closing PR.
Comment #8 by dlang-bot — 2022-09-05T19:19:35Z
@ibuclaw created dlang/dmd pull request #14419 "Revert "fix Issue 19662 - x86_64: Different code output when compiling with i…"" mentioning this issue: - Revert "fix Issue 19662 - x86_64: Different code output when compiling with inline/boundscheck on/off (#11944)" This reverts commit ff4007610173a2cea724b73bc6c1feb44069b435. https://github.com/dlang/dmd/pull/14419
Comment #9 by skocznymr — 2022-11-01T20:56:15Z
Any idea why it works on run.dlang.io even when adding same compiler switches?
Comment #10 by robert.schadek — 2024-12-13T19:02:21Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19537 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB