<< Back to previous view

[PCC-406] spurious warning for 'shift larger than type' of unaligned packed bitfield Created: 01/Sep/12  Updated: 02/Sep/12

Status: Resolved
Project: pcc
Component/s: C frontend
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major
Reporter: Iain Hibbert Assignee: Anders Magnusson
Resolution: Fixed Votes: 0
Environment: NetBSD/i386


 Description   
I see a spurious warning when shifting an packed bitfield which is not aligned on a word boundary, as demonstrated by the following code fragment

struct foo {
    unsigned a:8;
    unsigned b:8;
    unsigned c:8;
    unsigned d:8;
    unsigned e:8;
    unsigned f:8;
};

struct foo a;
struct foo b __attribute__ ((__packed__));

void foo(void)
{
    unsigned long t;

    t = a.a << 24;
    t = a.b << 24;
    t = a.c << 24;
    t = a.d << 24;
    t = a.e << 24;
    t = a.f << 24;

    t = b.a << 24;
    t = b.b << 24; // xx
    t = b.c << 24; // xx
    t = b.d << 24; // xx
    t = b.e << 24;
    t = b.f << 24; // xx
}

which produces a warning for the marked lines
test.c, line 25: warning: shift larger than type
test.c, line 26: warning: shift larger than type
test.c, line 27: warning: shift larger than type
test.c, line 29: warning: shift larger than type

(the code handling RS looks familiar, not sure if affected also)

 Comments   
Comment by Anders Magnusson [ 01/Sep/12 06:11 PM ]
Hm, even worse, the code generated is incorrect :-/
Just for the record; the attribute packed as given should not pack the struct, only allow the declared variable to have an alignment smaller than the usual struct alignment.
Comment by Anders Magnusson [ 02/Sep/12 10:39 AM ]
Fixed now.
Generated at Fri Dec 26 22:23:57 CET 2014 using JIRA Enterprise Edition, Version: 3.13.1-#333.