The following code fails with an assertion failure when it clearly shouldn't:
====================================================
void main()
{
float[64] array;
int i = 42;
auto slice = array[];
slice[] *= 2f;
assert(i == 42);
}
====================================================
Array bounds checking doesn't catch this. I presume that the code in the runtime to execute this array operation is buggy.
Comment #1 by eriatarka84 — 2010-01-08T06:53:11Z
Created attachment 548
patch against druntime to fix the problem
Comment #2 by eriatarka84 — 2010-01-08T06:55:22Z
Yes, it is buggy. I've uploaded a patch to fix the routine which does float array times scalar multiplication, though probably it's a better idea to file it at druntime directly. I'll crosspost it there.
Comment #3 by eriatarka84 — 2010-01-08T09:20:06Z
I've realized that the other float array operations of the form "array op= scalar" suffer from the same problem. Please hold off with applying this patch, I'll provide a more general one. I hope string mixins are ok to use in druntime? There's quite a lot of code duplication in these array modules.
Comment #4 by eriatarka84 — 2010-01-18T01:41:19Z
I submitted the patch to Tango (since that's what I use currently), it was folded into their copy of the runtime. I would appreciate if someone merged the changes into druntime to keep them in lockstep. Patch and discussion are here:
http://www.dsource.org/projects/tango/ticket/1831
Comment #5 by clugdbug — 2010-01-20T06:56:52Z
The original test case passes on D2, but here's a test case which fails on both D1 and D2.
------
void main()
{
float[66] array;
array[] = 0;
array[64] = 42;
array[65] = 43;
array[0..64] *= 2f;
assert(array[65] == 43);
assert(array[64] == 42);
}
------
Comment #6 by clugdbug — 2010-01-21T04:00:30Z
Changes checked into druntime svn 234 and D1 phobos svn 1403.