From: Derek M Jones <derek@knosof.co.uk>
To: Al Viro <viro@ZenIV.linux.org.uk>
Cc: linux-sparse@vger.kernel.org
Subject: Re: bitfields treatment
Date: Sat, 21 Mar 2009 21:57:41 +0000 [thread overview]
Message-ID: <49C562D5.40103@knosof.co.uk> (raw)
In-Reply-To: <20090320213727.GJ28946@ZenIV.linux.org.uk>
Al,
> * standard wording is such that it does *NOT* have integer promotions applied
> to such bitfields, even if the size is smaller than int. Arguably, that's
> a hole in standard; in any case, both gcc and sparse *do* integer promotions
> on those, with the same behaviour as usual (value-preserving promotion).
The usual arithmetic conversions (of which integer promotion is a
subset) are performed where the standard says they are performed,
bit-field involving an implementation defined type or not.
> * for all bitfields we are told that they act as (signed or unsigned)
> integer types of specified width. That has interesting implications:
See:
http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_315.htm
> unsigned long long f(unsigned long long n)
> {
> struct {
> unsigned long long n:33;
> } x = {n};
> return x.n + x.n;
> }
>
> *must* be equivalent to (n + n) & 0x1ffffffff on all implementations that
> allow such bitfields. I.e. these suckers are not promoted to base type;
Sentence 1162 says otherwise:
http://c0x.coding-guidelines.com/6.5.6.html
> they act as if we really head 33bit unsigned type, usual conversions in
> x.n + x.n left the result with that type and addition had been done within
> that type.
>
> gcc does it that way, we do not (x.n gets promoted to unsigned long long).
It has been argued at WG14 that gcc gets it wrong.
> What happens when we mix two such suckers with the same width?
At the very least sparse should generate a useful message.
--
Derek M. Jones tel: +44 (0) 1252 520 667
Knowledge Software Ltd mailto:derek@knosof.co.uk
Source code analysis http://www.knosof.co.uk
next prev parent reply other threads:[~2009-03-21 21:57 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-03-20 21:37 bitfields treatment Al Viro
2009-03-21 21:57 ` Derek M Jones [this message]
2009-03-21 23:12 ` Al Viro
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=49C562D5.40103@knosof.co.uk \
--to=derek@knosof.co.uk \
--cc=linux-sparse@vger.kernel.org \
--cc=viro@ZenIV.linux.org.uk \
/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.