www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 3583] New: Unsigned right shift works the same as signed right shift.

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3583

           Summary: Unsigned right shift works the same as signed right
                    shift.
           Product: D
           Version: future
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Keywords: wrong-code
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: dsimcha yahoo.com


--- Comment #0 from David Simcha <dsimcha yahoo.com> 2009-12-06 12:15:14 PST ---
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

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 06 2009
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3583


David Simcha <dsimcha yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |regression


--- Comment #1 from David Simcha <dsimcha yahoo.com> 2009-12-06 12:18:47 PST ---
Only happens on 2.037, so it's a regression.  Also only happens when compiled
with -O.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 06 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3583


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |clugdbug yahoo.com.au
            Version|future                      |2.036
            Summary|Unsigned right shift works  |Regression(DMD2.037):
                   |the same as signed right    |Unsigned right shift works
                   |shift.                      |the same as signed right
                   |                            |shift.


--- Comment #2 from Don <clugdbug yahoo.com.au> 2009-12-30 11:26:03 PST ---
Doesn't seem to happen on DMD1. Code works on DMD1.054beta.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 30 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3583


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch


--- Comment #3 from Don <clugdbug yahoo.com.au> 2009-12-30 12:06:31 PST ---
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;
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 30 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3583


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla digitalmars.com


--- Comment #4 from Walter Bright <bugzilla digitalmars.com> 2009-12-30
17:07:16 PST ---
Changeset 322

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 30 2009
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3583


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


--- Comment #5 from Walter Bright <bugzilla digitalmars.com> 2009-12-31
11:20:59 PST ---
Fixed dmd 2.038

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 31 2009