linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
To: Lance Richardson <lrichard@redhat.com>
Cc: linux-sparse@vger.kernel.org
Subject: Re: [PATCH v2] sparse: add support for static assert
Date: Mon, 25 Jan 2016 19:48:06 +0100	[thread overview]
Message-ID: <20160125184804.GA43341@macpro.local> (raw)
In-Reply-To: <1452551482-1250-1-git-send-email-lrichard@redhat.com>

On Mon, Jan 11, 2016 at 05:31:22PM -0500, Lance Richardson wrote:


Hi,

I don't understand why tha parsing part have changed so much since v1.
Is it because I said
   > It seems a bit strange to me to use NS_TYPEDEF, as this is unrelated types.
   > OTOH, the other namespaces deosn't seems better suited,
   > and yes C11 define this as sort of declaration, so ...
or because something related to handling it inside structs and unions or
for some other reason?

If because of the NS_TYPEDEF thing, sorry if I wasn't clear but I really think
it was fine, just that at first sight I found it strange.
If because the structs & unions, please explain why is it needed, what was wrong
with v1 and is fine now.


> diff --git a/validation/static_assert.c b/validation/static_assert.c
> new file mode 100644
> index 0000000..d3da954
> --- /dev/null
> +++ b/validation/static_assert.c
...
> +struct s2 {
> +	char c;
> +	_Static_assert(sizeof(struct s2) == 1, "struct sizeof");
> +};

This succeed but
	struct s2 {
		char c;
		_Static_assert(sizeof(struct s2) == 1, "struct sizeof");
		char d;
		_Static_assert(sizeof(struct s2) == 2, "struct sizeof");
	};
succeed also wich seems certainly very odd.

However it's not a problem with your patch but because of:
1) sparse is fine with the evaluation of sizeof(struct ...) while the struct
   is not yet completed (which is maybe usefull but certainly can also be
   considered as a bug)
2) those assertions are evaluated at parse time and not at some later time.
   My first thought was that we really should move the checking of those
   assertions at a later time, maybe after linearization and by introducing
   a new operation for it (like OP_ASSERT or so).
   But this is not a solution for the assertions inside structs & unions.
   I'll add a separate test case showing the problem and it's probably better
   to not put this test in your test cases.

Regards,
Luc

  reply	other threads:[~2016-01-25 18:48 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-11 22:31 [PATCH v2] sparse: add support for static assert Lance Richardson
2016-01-25 18:48 ` Luc Van Oostenryck [this message]
2016-01-28 14:53   ` Lance Richardson
2016-01-29 16:15     ` Luc Van Oostenryck

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=20160125184804.GA43341@macpro.local \
    --to=luc.vanoostenryck@gmail.com \
    --cc=linux-sparse@vger.kernel.org \
    --cc=lrichard@redhat.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).