* packed struct sizeof wrong
@ 2010-05-28 12:45 Johannes Berg
0 siblings, 0 replies; only message in thread
From: Johannes Berg @ 2010-05-28 12:45 UTC (permalink / raw)
To: Linux-Sparse
Hi all,
I ran across this in some of my kernel code, and isolated it into a few
test cases, below. sparse should not report errors on this file, but
does regardless, somehow the structs appear larger to it than they are.
johannes
This is suitable for dropping into the validation directory:
--- begin file ---
struct A {
unsigned char a, b, c, d;
} __attribute__((packed));
struct B {
struct A A;
unsigned char e, f;
unsigned short g;
unsigned char h;
} __attribute__((packed));
struct C {
unsigned char a, b, c, d;
unsigned char e, f;
unsigned short g;
unsigned char h;
} __attribute__((packed));
struct D {
unsigned char h;
} __attribute__((packed));
struct E {
unsigned short g;
unsigned char h;
} __attribute__((packed));
#define BUILD_BUG_ON(expr) ((void)(sizeof(struct { int:-!!(expr); })))
static inline void foo(void)
{
BUILD_BUG_ON(sizeof(struct A) != 4);
BUILD_BUG_ON(sizeof(struct B) != 9);
BUILD_BUG_ON(sizeof(struct C) != 9);
BUILD_BUG_ON(sizeof(struct D) != 1);
BUILD_BUG_ON(sizeof(struct E) != 3);
}
/*
* check-name: packed struct sizeof
*/
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2010-05-28 12:45 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-05-28 12:45 packed struct sizeof wrong Johannes Berg
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).