linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
To: Ramsay Jones <ramsay@ramsayjones.plus.com>
Cc: linux-sparse@vger.kernel.org, Jacob Keller <jacob.e.keller@intel.com>
Subject: Re: [PATCH v2 05/16] add testcases for packed structures
Date: Mon, 28 Dec 2020 21:01:50 +0100	[thread overview]
Message-ID: <20201228200150.xvvrfno2e3mol7v4@ltop.local> (raw)
In-Reply-To: <860fe109-6819-ec55-e55f-90812b9f90f2@ramsayjones.plus.com>

On Mon, Dec 28, 2020 at 04:17:36PM +0000, Ramsay Jones wrote:
> 
> 
> On 26/12/2020 17:51, Luc Van Oostenryck wrote:
> > Currently, packed structs are not handled correctly.
> > 
> > Add some testcases for them.
> > 
> > Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
> > ---
> >  validation/packed-deref0.c | 24 ++++++++++++++++++++++++
> >  validation/packed-struct.c | 33 +++++++++++++++++++++++++++++++++
> >  2 files changed, 57 insertions(+)
> >  create mode 100644 validation/packed-deref0.c
> >  create mode 100644 validation/packed-struct.c
> > 
> > diff --git a/validation/packed-deref0.c b/validation/packed-deref0.c
> > new file mode 100644
> > index 000000000000..865ad68a4f37
> > --- /dev/null
> > +++ b/validation/packed-deref0.c
> > @@ -0,0 +1,24 @@
> > +#define	__packed	__attribute__((packed))
> > +
> > +typedef struct {
> > +	__INT8_TYPE__	a;
> > +	__INT16_TYPE__	b;
> > +	__INT32_TYPE__	c;
> > +} __packed obj_t;
> > +
> > +_Static_assert(sizeof(obj_t) == 7, "sizeof packed struct");
> > +
> > +static void foo(obj_t *ptr, int val)
> > +{
> > +	ptr->c = val;
> > +}
> > +
> > +static void bar(obj_t o)
> > +{
> > +	foo(&o, 0);
> > +}
> > +
> > +/*
> > + * check-name: packed-deref0
> > + * check-known-to-fail
> > + */
> > diff --git a/validation/packed-struct.c b/validation/packed-struct.c
> > new file mode 100644
> > index 000000000000..5039be4d0b45
> > --- /dev/null
> > +++ b/validation/packed-struct.c
> > @@ -0,0 +1,33 @@
> > +#define __packed __attribute__((packed))
> > +
> > +typedef unsigned char   u8;
> > +typedef __UINT16_TYPE__ u16;
> > +typedef __UINT32_TYPE__ u32;
> > +typedef __UINT64_TYPE__ u64;
> > +
> > +struct a {
> > +	u8 a;
> > +	u8 b;
> > +	u16 c;
> > +} __packed;
> > +_Static_assert(__alignof(struct a) == 1, "align struct");
> > +_Static_assert(   sizeof(struct a) == sizeof(u32), " size struct");
> 
> Hmm, I don't think '== sizeof(u32)' is any better than '== 4'.

Yes, I agree.

-- Luc 

  reply	other threads:[~2020-12-28 23:13 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-26 17:51 [PATCH 00/16] support __packed struct Luc Van Oostenryck
2020-12-26 17:51 ` [PATCH v2 01/16] add testcases for dubious enum values Luc Van Oostenryck
2020-12-26 17:51 ` [PATCH v2 02/16] add testcases for exotic " Luc Van Oostenryck
2020-12-28 16:10   ` Ramsay Jones
2020-12-28 20:00     ` Luc Van Oostenryck
2020-12-26 17:51 ` [PATCH v2 03/16] add testcases for enum attributes Luc Van Oostenryck
2020-12-26 17:51 ` [PATCH v2 04/16] add testcases for type attributes Luc Van Oostenryck
2020-12-28 16:13   ` Ramsay Jones
2020-12-28 19:59     ` Luc Van Oostenryck
2020-12-26 17:51 ` [PATCH v2 05/16] add testcases for packed structures Luc Van Oostenryck
2020-12-28 16:17   ` Ramsay Jones
2020-12-28 20:01     ` Luc Van Oostenryck [this message]
2020-12-26 17:51 ` [PATCH v2 06/16] add testcases for packed bitfields Luc Van Oostenryck
2020-12-28 16:28   ` Ramsay Jones
2020-12-28 20:05     ` Luc Van Oostenryck
2020-12-26 17:51 ` [PATCH v2 07/16] apply_ctype: use self-explanatory argument name Luc Van Oostenryck
2020-12-26 17:51 ` [PATCH v2 08/16] apply_ctype: reverse the order of arguments Luc Van Oostenryck
2020-12-28 16:47   ` Ramsay Jones
2020-12-28 20:37     ` Luc Van Oostenryck
2020-12-26 17:51 ` [PATCH v2 09/16] apply_ctype: move up its declaration Luc Van Oostenryck
2020-12-26 17:51 ` [PATCH v2 10/16] struct-attr: prepare to handle attributes at the end of struct definitions (1) Luc Van Oostenryck
2020-12-28 16:54   ` Ramsay Jones
2020-12-28 20:49     ` Luc Van Oostenryck
2020-12-26 17:51 ` [PATCH v2 11/16] struct-attr: prepare to handle attributes at the end of struct definitions (2) Luc Van Oostenryck
2020-12-26 17:51 ` [PATCH v2 12/16] struct-attr: prepare to handle attributes at the end of struct definitions (3) Luc Van Oostenryck
2020-12-26 17:51 ` [PATCH v2 13/16] struct-attr: fix type attribute like 'struct __attr { ... }' Luc Van Oostenryck
2020-12-26 17:51 ` [PATCH v2 14/16] struct-attr: fix: do not ignore struct/union/enum type attributes Luc Van Oostenryck
2020-12-26 17:51 ` [PATCH v2 15/16] packed: no out-of-bound access of packed bitfields Luc Van Oostenryck
2020-12-28 17:10   ` Ramsay Jones
2020-12-28 21:12     ` Luc Van Oostenryck
2020-12-26 17:51 ` [PATCH v2 16/16] packed: add support for __packed struct Luc Van Oostenryck
2020-12-28 17:18 ` [PATCH 00/16] support " Ramsay Jones
2020-12-28 21:33   ` Luc Van Oostenryck
2021-01-05 17:56     ` Jacob Keller
2021-01-05 20:39       ` Luc Van Oostenryck
2021-01-05 22:07         ` Jacob Keller
2021-01-05 17:55 ` Jacob Keller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201228200150.xvvrfno2e3mol7v4@ltop.local \
    --to=luc.vanoostenryck@gmail.com \
    --cc=jacob.e.keller@intel.com \
    --cc=linux-sparse@vger.kernel.org \
    --cc=ramsay@ramsayjones.plus.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).