D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 3583 - Regression(DMD2.037): Unsigned right shift works the same as signed right shift.
Summary: Regression(DMD2.037): Unsigned right shift works the same as signed right shift.
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: Other Windows
: P2 regression
Assignee: No Owner
URL:
Keywords: patch, wrong-code
Depends on:
Blocks:
 
Reported: 2009-12-06 12:15 UTC by David Simcha
Modified: 2015-06-09 01:27 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 David Simcha 2009-12-06 12:15:14 UTC
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 David Simcha 2009-12-06 12:18:47 UTC
Only happens on 2.037, so it's a regression.  Also only happens when compiled with -O.
Comment 2 Don 2009-12-30 11:26:03 UTC
Doesn't seem to happen on DMD1. Code works on DMD1.054beta.
Comment 3 Don 2009-12-30 12:06:31 UTC
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 Walter Bright 2009-12-30 17:07:16 UTC
Changeset 322
Comment 5 Walter Bright 2009-12-31 11:20:59 UTC
Fixed dmd 2.038