www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 8876] New: bitfields template generate wrong code

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

           Summary: bitfields template generate wrong code
           Product: D
           Version: D2
          Platform: x86_64
        OS/Version: Linux
            Status: NEW
          Severity: major
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: kozzi11 gmail.com



Created an attachment (id=1151)
Problematic use case

mixin(bitfields!(
    uint, "machine", 24,
    ushort, "pid", 16,
    uint, "inc", 24
));

generate for machine field this code:

 property  safe void machine(uint v) pure nothrow {
        assert(v >= machine_min);
        assert(v <= machine_max); 
        _machine_pid_inc = cast(typeof(_machine_pid_inc)) ((_machine_pid_inc &
~16777215U) | ((cast(typeof(_machine_pid_inc)) v << 0U) & 16777215U));
}

but this is wrong because _machine_pid_inc & ~16777215U clear some other bits;
it should generate code like this:

 property  safe void machine(uint v) pure nothrow {
        assert(v >= machine_min);
        assert(v <= machine_max); 
        _machine_pid_inc = cast(typeof(_machine_pid_inc)) ((_machine_pid_inc &
~16777215UL) | ((cast(typeof(_machine_pid_inc)) v << 0U) & 16777215U));
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 23 2012
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8876




Commits pushed to master at https://github.com/D-Programming-Language/phobos

https://github.com/D-Programming-Language/phobos/commit/b15c4205da0d0708dde6e766d3e2ab976c7457d2
Fixes Issue 8876 - bitfields template generate wrong code

https://github.com/D-Programming-Language/phobos/commit/ce62efce7408a7780a24031048882f0e6d565674


Fix issue 8876

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 25 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8876


Daniel Kozak <kozzi11 gmail.com> changed:

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


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 25 2012