Comment #0 by iselix1988+dbugzilla — 2012-07-03T10:47:09Z
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
}
---
Comment #1 by hsteoh — 2012-11-08T21:05:43Z
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.
Comment #2 by hsteoh — 2012-11-08T21:21:22Z
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).
Comment #3 by github-bugzilla — 2012-11-09T00:11:48Z