Bug 4184 – associative array with certain key types results in corrupt values during iteration

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Linux
Creation time
2010-05-13T10:38:00Z
Last change time
2014-02-15T02:42:06Z
Assigned to
nobody
Creator
schveiguy

Comments

Comment #0 by schveiguy — 2010-05-13T10:38:05Z
The following code: import std.stdio; void main() { uint[ushort] aa; aa[1] = 1; aa[2] = 2; aa[3] = 3; aa[4] = 4; aa[5] = 5; writefln("%s", aa); foreach(ushort k, uint v; aa) { writefln("%s => %s", k, v); } } results in the following output: [4:4,1:1,5:5,2:2,3:3] 4 => 262144 1 => 65536 5 => 327680 2 => 131072 3 => 196608 Clearly, the data is stored correctly, or else writefln would not be able to get the correct values when displaying the AA directly. However, the iteration code is getting corrupt values. I suspect this is probably a druntime issue. It was introduced somewhere between 2.033 (which works) and 2.036 (I haven't yet downloaded the intermediate versions). I will see if I can find the cause and commit a patch.
Comment #1 by schveiguy — 2010-05-13T11:02:08Z
wow, nevermind, it is probably dmd. Compiling this simple function results in pages and pages of AA functions in disassembly, I'm not sure if druntime has anything to do with this bug. void foo(uint[ushort] aa) { foreach(ushort k, uint v; aa) { } }
Comment #2 by bugzilla — 2010-05-13T17:19:42Z
Printing things in hex yields 40000, 10000, 50000, 20000, 30000. Hmm.
Comment #3 by bugzilla — 2010-05-13T17:55:50Z
changeset 295
Comment #4 by schveiguy — 2010-05-13T19:46:10Z
Great, thanks! No wonder there was so much code generated, it's a template :) I didn't know the compiler associated AA's with a template. I'll test against dcollections tomorrow.
Comment #5 by schveiguy — 2010-05-14T04:31:27Z
I confirm, it fixes the problems in dcollections, thanks.
Comment #6 by schveiguy — 2010-05-19T10:15:28Z
*** Issue 4209 has been marked as a duplicate of this issue. ***