All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Given <dg@cowlark.com>
To: linux-sparse@vger.kernel.org
Subject: Re: [PATCH 2/15 v2] Unhardcode byte size being 8 bits.
Date: Wed, 17 Dec 2008 23:33:59 +0000	[thread overview]
Message-ID: <49498C67.4000700@cowlark.com> (raw)
In-Reply-To: <20081217190534.24084.94887.stgit@zaytsev.su>

[-- Attachment #1: Type: text/plain, Size: 1562 bytes --]

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).

> 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.

-- 
┌─── dg@cowlark.com ───── http://www.cowlark.com ─────
│ "A line dancer near a graduated cylinder, the blithe spirit inside
│ some wheelbarrow, and a tomato are what made America great!" --=

  reply	other threads:[~2008-12-18  0:07 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 [this message]
2008-12-18  0:33   ` Alexey Zaytsev
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=49498C67.4000700@cowlark.com \
    --to=dg@cowlark.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.