Tricky DMD bug, but I have no idea how to report
JN
666total at wp.pl
Mon Dec 17 21:59:59 UTC 2018
Hey guys,
while working on my game engine project, I encountered a DMD
codegen bug. It occurs only when compiling in release mode, debug
works. Unfortunately I am unable to minimize the code, since it's
quite a bit of code, and changing the code changes the bug
occurrence. Basically my faulty piece of code looks like this
class Texture2D {}
auto a = new Texture2D();
auto b = new Texture2D();
auto c = new Texture2D();
Texture2D[int] TextureBindings;
writeln(a, b, c);
textureBindings[0] = a;
textureBindings[1] = b;
textureBindings[2] = c;
writeln(textureBindings);
and the output is:
Texture2DTexture2DTexture2D
[0:null, 2:null, 1:null]
I'd expect it to output:
Texture2DTexture2DTexture2D
[0:Texture2D, 2:Texture2D, 1:Texture2D]
depending on what I change around this code, for example changing
it to
writeln(a, " ", b, " ", c);
results in output of:
Texture2D Texture2D Texture2D
[0:Texture2D, 2:null, 1:null]
It feels completely random. Removing, adding calls completely
unrelated to these changes the result. My guess is that the
compiler somehow reorders the calls incorrectly, changing the
semantics. Trick is, LDC works correctly and produces the
expected result, both when compiling in debug and release mode.
I tried to play around with assoc arrays on run.dlang.io but
could never reproduce it. It has to do something with the way my
code works and possibly interacts with other C libraries. Does
anyone have an idea what could it be and how to reproduce it so
that it can be reported and fixed? For now, I'll just switch to
LDC, but I feel bad leaving a possible bug intact and unreported.
This is with DMD32 D Compiler v2.083.1, on Windows, x86_64
compilation target.
More information about the Digitalmars-d-learn
mailing list