http://d.puremagic.com/issues/show_bug.cgi?id=10876

           Summary: foreach and remove over associative array causes
                    invalid data to appear
           Product: D
           Version: D2
          Platform: x86_64
        OS/Version: Linux
            Status: NEW
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: [email protected]
        ReportedBy: [email protected]


--- Comment #0 from Maxime Chevalier-Boisvert <[email protected]> 
2013-08-23 09:35:40 PDT ---
This issue shows up using DMD64 D Compiler v2.063 on Linux.

I have a foreach loop in which I remove values from an associative array. The
behavior is completely broken. Items which are not in the associative array
(including the null value!) end up appearing in the iteration. The following
code snippet from my compiler produces the issue:

writeln("associative array length: ", allocState.length);
writeln("keys length: ", allocState.keys.length);

// Remove dead values from the alloc state
foreach (value, allocSt; allocState)
{
    writeln("key: ", value);
    writeln((value in allocState)? true:false);

    if (value is null)
        writeln(allocState[null]);

    if (liveInfo.liveAtEntry(value, block) is false)
        allocState.remove(value);
}

The output is as follows:

associative array length: 4
keys length: 4
key: $22 = arg 6 "v"
true
key: $20 = arg 4 "o"
true
key: $8 = add_i32 $1, $21
true
key: $21 = arg 5 "i"
true
key: $7 = phi [call_reg(5662):0 => $14, call_cont(565C):0 => $12]
false
key: $12 = load_u32 $20, $11
false
key: $12 = load_u32 $20, $11
false
key: $1 = add_i32 32, $0
false
key: $1 = add_i32 32, $0
false
key: $0 = mul_i32 8, $7
false
key: $0 = mul_i32 8, $7
false
key: null
false
[email protected](1410): Range violation

As you can see, most of the keys listed are not in the associative array, and
the null value appears as a key, out of nowhere, which causes a crash.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------

Reply via email to