When using *= operator with -1 of constant value for long array element , it breaks next element value . See code below: --- void main(){ int[] ia = [1,2,3,4,5]; long[] la = [1,2,3,4,5]; ia[2] *= -1; la[2] *= -1; assert(ia == [1,2,-3,4,5]); // OK in x86 and x64 assert(la == [1,2,-3,4,5]); // OK in x86 but Failed in x64 // la == [1,2,-3,-5,5] in x64 } ---
Tested on dmd git HEAD and gdc 4.7 (2.058); the bug only happens on dmd -m64. Not sure if this is a regression, or if it's a dmd backend bug.
Hmm, looks like a dmd backend bug: gdc (unoptimized) produces neg (respectively negl) instructions for negating the array element of ia (resp. la), but dmd -m64 produces negl (resp. negq) instead. This produces correct results for la, because dmd actually generates it as a quad array, whereas ia remains an int array. This is a violation of the D spec (which states that int==32 bits and long==64 bits; seems like the dmd backend is wrongly using int==32 bits and long==128 bits (inconsistently).
Commit pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/af7b7f098a6e91c34993f43d3afda54e54a96a4e fix Issue 8340 - *= operator breaks long array in x64
Commit pushed to dmd-1.x at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/74eee15c8ed326f53bed4956e772064a4ee6e246 fix Issue 8340 - *= operator breaks long array in x64