Bug 3583 – Regression(DMD2.037): Unsigned right shift works the same as signed right shift.

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Windows
Creation time
2009-12-06T12:15:00Z
Last change time
2015-06-09T01:27:03Z
Keywords
patch, wrong-code
Assigned to
nobody
Creator
dsimcha

Comments

Comment #0 by dsimcha — 2009-12-06T12:15:14Z
import std.stdio; void main() { int i = 0b10000000_00000000_00000000_00000010; int iSigned = i >> 2; writefln(" int >>: %.32b", iSigned); int iUnsigned = i >>> 2; writefln(" int >>>: %.32b", iUnsigned); uint u = cast(uint) i; uint uSigned = u >> 2; writefln(" uint >>: %.32b", uSigned); uint uUnsigned = u >>> 2; writefln("uint >>>: %.32b", uUnsigned); } Output (DMD 2.037): int >>: 11100000000000000000000000000000 int >>>: 11100000000000000000000000000000 uint >>: 00100000000000000000000000000000 uint >>>: 00100000000000000000000000000000
Comment #1 by dsimcha — 2009-12-06T12:18:47Z
Only happens on 2.037, so it's a regression. Also only happens when compiled with -O.
Comment #2 by clugdbug — 2009-12-30T11:26:03Z
Doesn't seem to happen on DMD1. Code works on DMD1.054beta.
Comment #3 by clugdbug — 2009-12-30T12:06:31Z
Root cause: A bad refactoring that dropped the conversion to unsigned. PATCH: e2ir.c, line 3008 and 3113 UshrExp::toElem() and UshrAssignExp::toElem() Copy the code from D1. elem *UshrAssignExp::toElem(IRState *irs) { - return toElemBin(irs, OPshrass); + elem *eleft = e1->toElem(irs); + eleft->Ety = touns(eleft->Ety); + elem *eright = e2->toElem(irs); + elem *e = el_bin(OPshrass, type->totym(), eleft, eright); + el_setLoc(e, loc); + return e; } elem *UshrExp::toElem(IRState *irs) { - return toElemBin(irs, OPshr); + elem *eleft = e1->toElem(irs); + eleft->Ety = touns(eleft->Ety); + elem *eright = e2->toElem(irs); + elem *e = el_bin(OPshr, type->totym(), eleft, eright); + el_setLoc(e, loc); + return e; }
Comment #4 by bugzilla — 2009-12-30T17:07:16Z
Changeset 322
Comment #5 by bugzilla — 2009-12-31T11:20:59Z
Fixed dmd 2.038