Re: [PATCH v2 06/16] add testcases for packed bitfields

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Dec 28, 2020 at 04:28:24PM +0000, Ramsay Jones wrote:
> 
> 
> On 26/12/2020 17:51, Luc Van Oostenryck wrote:
> > Currently, packed bitfields are not handled correctly.
> > 
> > Add some testcases for them.
> > 
> > Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx>
> > ---
> >  validation/packed-bitfield0.c | 67 +++++++++++++++++++++++++++++++++++
> >  validation/packed-bitfield1.c | 28 +++++++++++++++
> >  validation/packed-bitfield2.c | 16 +++++++++
> >  validation/packed-bitfield3.c | 29 +++++++++++++++
> >  validation/packed-bitfield4.c | 19 ++++++++++
> >  validation/packed-bitfield5.c | 21 +++++++++++
> >  6 files changed, 180 insertions(+)
> >  create mode 100644 validation/packed-bitfield0.c
> >  create mode 100644 validation/packed-bitfield1.c
> >  create mode 100644 validation/packed-bitfield2.c
> >  create mode 100644 validation/packed-bitfield3.c
> >  create mode 100644 validation/packed-bitfield4.c
> >  create mode 100644 validation/packed-bitfield5.c
> > 
> > diff --git a/validation/packed-bitfield0.c b/validation/packed-bitfield0.c
> > new file mode 100644
> > index 000000000000..907500dedbf0
> > --- /dev/null
> > +++ b/validation/packed-bitfield0.c
> > @@ -0,0 +1,67 @@
> > +#define alignof(X)	__alignof__(X)
> > +#define __packed	__attribute__((packed))
> > +
> > +struct sa {
> > +	int a:7;
> > +	int c:10;
> > +	int b:2;
> > +} __packed;
> > +_Static_assert(alignof(struct sa) == 1, "alignof(struct sa)");
> > +_Static_assert( sizeof(struct sa) == 3,  "sizeof(struct sa)");
> > +
> > +struct __packed sb {
> > +	int a:7;
> > +	int c:10;
> > +	int b:2;
> > +};
> > +_Static_assert(alignof(struct sb) == 1, "alignof(struct sb)");
> > +_Static_assert( sizeof(struct sb) == 3,  "sizeof(struct sb)");
> 
> Why 'struct sb'? It is not used in the rest of the test (and is
> identical to 'struct sa').

Good question :)
I've probably reused some previous file as a kind of template.
 
> > diff --git a/validation/packed-bitfield3.c b/validation/packed-bitfield3.c
> > new file mode 100644
> > index 000000000000..6acff875299f
> > --- /dev/null
> > +++ b/validation/packed-bitfield3.c
> > @@ -0,0 +1,29 @@
> > +#define __packed __attribute__((packed))
> > +
> > +typedef unsigned char   u8;
> > +typedef __UINT16_TYPE__ u16;
> > +typedef __UINT32_TYPE__ u32;
> > +typedef __UINT64_TYPE__ u64;
> > +
> > +struct b {
> > +	u32	a:1;
> > +	u32	b:2;
> > +	u32	c:4;
> > +	u32	d:8;
> > +	u32	e:16;
> > +} __packed;
> > +_Static_assert(__alignof(struct b) == 1);
> > +_Static_assert(   sizeof(struct b) == sizeof(u32));
> 
> Again '== sizeof(u32)' does not seem useful. (what is it
> trying to say?)
> 
> > +
> > +struct c {
> > +	u8	a;
> > +	u8	b;
> > +	u64	c:48;
> > +} __packed;
> > +_Static_assert(__alignof(struct c) == 1);
> > +_Static_assert(   sizeof(struct c) == sizeof(u64));
> 
> ditto.

Yes, I agree.

-- Luc 



[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux