Thread overview
[Issue 8876] New: bitfields template generate wrong code
Oct 23, 2012
Daniel Kozak
Oct 25, 2012
Daniel Kozak
October 23, 2012
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


--- Comment #0 from Daniel Kozak <kozzi11@gmail.com> 2012-10-23 00:11:22 PDT ---
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: -------
October 25, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8876



--- Comment #1 from github-bugzilla@puremagic.com 2012-10-25 06:25:18 PDT ---
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 Merge pull request #886 from Kozzi11/master

Fix issue 8876

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 25, 2012
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: -------