D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 8340 - *= operator breaks long array in x64
Summary: *= operator breaks long array in x64
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86_64 Linux
: P2 major
Assignee: No Owner
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2012-07-03 10:47 UTC by iselix1988+dbugzilla
Modified: 2015-06-09 05:11 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description iselix1988+dbugzilla 2012-07-03 10:47:09 UTC
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 hsteoh 2012-11-08 21:05:43 UTC
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 hsteoh 2012-11-08 21:21:22 UTC
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 github-bugzilla 2012-11-09 00:11:48 UTC
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
Comment 4 github-bugzilla 2012-11-09 00:13:45 UTC
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