[Issue 10876] New: foreach and remove over associative array causes invalid data to appear

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Aug 23 09:35:42 PDT 2013


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: nobody at puremagic.com
        ReportedBy: maximechevalierb at gmail.com


--- Comment #0 from Maxime Chevalier-Boisvert <maximechevalierb at gmail.com> 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
core.exception.RangeError at jit.jit(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: -------


More information about the Digitalmars-d-bugs mailing list