5545 – [64-bit] DMD fails to postincrement ubytes.

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 5545 - [64-bit] DMD fails to postincrement ubytes.
Summary: [64-bit] DMD fails to postincrement ubytes.
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86_64 Windows
: P2 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
Reported: 2011年02月07日 16:38 UTC by David Simcha
Modified: 2011年02月07日 22:34 UTC (History)
1 user (show)

See Also:


Attachments
Add an attachment (proposed patch, testcase, etc.)

Note You need to log in before you can comment on or make changes to this issue.
Description David Simcha 2011年02月07日 16:38:10 UTC
I apologize for the length of this test case, it was reduced from a ~1500 line file with a failing unittest. The following bug seems to be caused by DMD failing to increment i in the struct Perm. It only happens under -O -release -m64. Omitting any of these flags makes this program work. Also, the call to enforce() is necessary to reproduce the bug.
import std.stdio;
bool enforce(bool value, lazy const(char)[] msg = null) {
 if(!value) {
 return false;
 }
 return value;
}
struct Perm {
 byte[3] perm;
 ubyte i;
 this(byte[] input) {
 foreach(elem; input) {
 enforce(i < 3);
 perm[i++] = elem;
 stderr.writeln(i); // Never gets incremented. Stays at 0.
 }
 }
}
void main() {
 byte[] stuff = [0, 1, 2];
 auto perm2 = Perm(stuff);
 writeln(perm2.perm); // Prints [2, 0, 0]
 assert(perm2.perm[] == [0, 1, 2]);
}


AltStyle によって変換されたページ (->オリジナル) /