public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "josh at joshtriplett dot org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/59852] Support sparse-style __attribute__((bitwise)) (type attribute)
Date: Tue, 21 Jan 2014 03:08:00 -0000	[thread overview]
Message-ID: <bug-59852-4-ZVFLutbSto@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-59852-4@http.gcc.gnu.org/bugzilla/>

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59852

--- Comment #8 from Josh Triplett <josh at joshtriplett dot org> ---
(In reply to Josh Triplett from comment #7)
> (In reply to Josh Triplett from comment #4)
> > Also note that arithmetic operations between a bitwise and a known-zero
> > value do not warn.
> > 
> > The warning on ~ of a value smaller than int only occurs if the value is not
> > subsequently stuffed back into the same bitwise type.  For instance, this
> > does not warn:
> > 
> > typedef unsigned short __attribute__((bitwise)) le16;
> > 
> > le16 i, j;
> > 
> > le16 k = ~i | j;
> 
> To elaborate on this with some implementation details of Sparse: applying ~
> to a bitwise type smaller than an int produces a value of a corresponding
> bitwise type with the added attribute "fouled".  Bitwise operations
> propagate the fouled bit if either operand has it, without warning.  == and
> != will warn about fouled types.  Assignments or conversions to the original
> unfouled bitwise type will work without warning, discarding the fouled bit. 
> And any arithmetic operation that would warn about a bitwise type will warn
> about a fouled type, complaining that the type degraded to "int".

One more detail: bitwise '&' of two fouled bitwise types will work and produce
the same fouled type; but bitwise '&' of a bitwise type and the corresponding
fouled bitwise type will produce the unfouled bitwise type.  For details, see
commit d24967cb847b7a04920698a9053ea8195046a831 in Sparse by Al Viro:

    Basically, we delay reporting an error on ~<short bitwise> for as long as
    possible in hope that taint will be cleansed later.  Exact rules follow:

            * ~short_bitwise => corresponding fouled
            * any arithmetics that would be banned for bitwise => same warning
    as if we would have bitwise
            * if t1 is bitwise type and t2 - its fouled analog, then
    t1 & t2 => t1, t1 | t2 => t2, t1 ^ t2 => t2.
            * conversion of t2 to t1 is silent (be it passing as argument
    or assignment).  Other conversions are banned.
            * x ? t1 : t2 => t2
            * ~t2 => t2 (_not_ t1; something like ~(x ? y : ~y) is still
fouled)
            * x ? t2 : t2 => t2, t2 {&,|,^} t2 => t2 (yes, even ^ - same as
before).
            * x ? t2 : constant_valid_for_t1 => t2
            * !t2 => warning, ditto for comparisons involving t2 in any way.
            * wrt casts t2 acts exactly as t1 would.
            * for sizeof, typeof and alignof t2 acts as promoted t1.  Note that
    fouled can never be an lvalue or have types derived from it - can't happen.


      parent reply	other threads:[~2014-01-21  3:08 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-17  5:32 [Bug c/59852] New: " hpa at zytor dot com
2014-01-17  9:39 ` [Bug c/59852] " josh at joshtriplett dot org
2014-01-20 23:46 ` tromey at gcc dot gnu.org
2014-01-21  0:00 ` hpa at zytor dot com
2014-01-21  0:39 ` josh at joshtriplett dot org
2014-01-21  2:34 ` tromey at gcc dot gnu.org
2014-01-21  2:45 ` josh at joshtriplett dot org
2014-01-21  2:54 ` josh at joshtriplett dot org
2014-01-21  3:08 ` josh at joshtriplett dot org [this message]

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=bug-59852-4-ZVFLutbSto@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.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 read-only IMAP folder(s) and NNTP newsgroup(s).