From: "Alexey Zaytsev" <alexey.zaytsev@gmail.com>
To: David Given <dg@cowlark.com>
Cc: linux-sparse@vger.kernel.org, Josh Triplett <josh@kernel.org>
Subject: Re: [PATCH 2/15 v2] Unhardcode byte size being 8 bits.
Date: Thu, 18 Dec 2008 03:33:45 +0300 [thread overview]
Message-ID: <f19298770812171633w43707eb0h8c0a0be262549ddf@mail.gmail.com> (raw)
In-Reply-To: <49498C67.4000700@cowlark.com>
On Thu, Dec 18, 2008 at 02:33, David Given <dg@cowlark.com> wrote:
> Alexey Zaytsev wrote:
> [...]
>> This problem may be addressed by changing bits_to_bytes to
>> static inline int bits_to_bytes(int bits)
>> {
>> return bits >= 0 ? bits / bits_in_char : -1;
>> }
>
> That's fine by me (although I've been using my version for ages now with
> no apparent problems --- just out of interest, Clue is now using Sparse
> to compile C into Lua, Javascript, Perl 5, Common Lisp, C and Java
> moderately successfully).
Just try to run sparse over the Linux kernel. It fireas at least at
void * pointer manipulation and (some?) offsetof()'s. Maybe
somewhere else.
>
>> But it seems there is also a bug in sparse, as in
>> ctype_declaration[] the bit_size of void_ctype is
>> set to NULL, while gcc assumes sizeof(void) being 1.
>> Currently sparse would generate wrong code for:
> [...]
>> unsigned long test1(void *p)
>> {
>> return sizeof(*p);
>> }
>
> TBH, I don't think that's legal --- I know of several compilers that
> will refuse to compile it, and gcc -pedantic produces a warning, which
> means it probably falls into the 'undefined behaviour' bucket of the
> standard. I can't find anything that specifically talks about sizeof
> void, but 6.3.2.2.1 prohibits doing *anything* with the result of an
> expression of type void, which sort of applies here.
>
> Of course, I'm thinking about this from the sparse-as-a-compiler point
> of view, where you're probably more interested in replicating gcc's
> behaviour.
This seems to be legal, and quite popular in the Linux kernel. GNU C defines
sizeof(void) being 1.And as it has the -Wpointer-arith flag, this kind of stuff
may be caught without sparse if deemed undesirable.
P.S:
Please, sign off this patch and the one adding type information to
struct instruction.
next prev parent reply other threads:[~2008-12-18 0:33 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-12-17 20:05 [PATCH 2/15 v2] Unhardcode byte size being 8 bits Alexey Zaytsev
2008-12-17 23:33 ` David Given
2008-12-18 0:33 ` Alexey Zaytsev [this message]
2008-12-18 0:58 ` David Given
2008-12-18 1:24 ` Alexey Zaytsev
2008-12-18 1:10 ` Derek M Jones
2008-12-18 1:52 ` Derek M Jones
2008-12-18 3:11 ` Alexey Zaytsev
2008-12-18 13:05 ` Derek M Jones
2008-12-18 17:07 ` Alexey Zaytsev
2008-12-18 17:12 ` David Given
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=f19298770812171633w43707eb0h8c0a0be262549ddf@mail.gmail.com \
--to=alexey.zaytsev@gmail.com \
--cc=dg@cowlark.com \
--cc=josh@kernel.org \
--cc=linux-sparse@vger.kernel.org \
/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).