Issue Details (XML | Word | Printable)

Key: PCC-366
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: Anders Magnusson
Reporter: Iain Hibbert
Votes: 0
Watchers: 0

If you were logged in you would be able to see more operations.

assignment to packed bitfield using wrong mask

Created: 02/Jul/11 12:22 PM   Updated: 30/Jul/11 10:06 AM
Component/s: C frontend
Affects Version/s: None
Fix Version/s: None


 Description  « Hide
the following code

struct foo {
        unsigned char a:3;
        unsigned short b:14;
} __attribute__((__packed__));

foo(struct foo *f)
        f->b = 123;

when compiled, causes the assembler to complain

/tmp/ctm.10685a: Assembler messages:
/tmp/ctm.10685a:15: Warning: -131065 shortened to 7

this is because the bitfield assignment is trying to AND a value too large for the instruction

        .align 4
        .globl foo
        .type foo,@function
        pushl %ebp
        movl %esp,%ebp
        subl $4,%esp
        movl 8(%ebp),%eax
        movl %eax,-4(%ebp)
        movl -4(%ebp),%eax
        movw (%eax),%ax
        andw $-131065,%ax ## <-----
        orw $984,%ax
        movl -4(%ebp),%edx
        movw %ax,(%edx)
        .size foo,.-foo
        .ident "PCC: pcc 1.1.0.DEVEL 20110701 for netbsd-i386"

the code is generated by trees.c after line 2420, but I'm not sure if its just because
'char' and 'short' types are not supported (should fail to compile, in that case?) or if
the wrong type is being used for the AND operation since andw is being emitted

in truth, I can't quite imagine how this structure is supposed to be laid out anyway
it seems wrong to use bit-fields and packed at the same time (this code this
example comes from is in usr.sbin/fwctl/fwdv.c on NetBSD, the structure being
defined in sys/dev/ieee1394/iec68113.h)

 All   Comments   Change History      Sort Order: Ascending order - Click to sort in descending order
Anders Magnusson made changes - 02/Jul/11 06:10 PM
Field Original Value New Value
Assignee Anders Magnusson [ ragge ]
Anders Magnusson made changes - 30/Jul/11 10:06 AM
Status Open [ 1 ] Resolved [ 5 ]
Resolution Fixed [ 1 ]