* [Bug c/59852] Support sparse-style __attribute__((bitwise)) (type attribute)
2014-01-17 5:32 [Bug c/59852] New: Support sparse-style __attribute__((bitwise)) (type attribute) hpa at zytor dot com
@ 2014-01-17 9:39 ` josh at joshtriplett dot org
2014-01-20 23:46 ` tromey at gcc dot gnu.org
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: josh at joshtriplett dot org @ 2014-01-17 9:39 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59852
--- Comment #1 from Josh Triplett <josh at joshtriplett dot org> ---
Note in particular the bit about typedefs. Two identical declarations both
using __attribute__((bitwise)) create two variables with different types, but
two declarations both usin the same typedef declared with
__attribute__((bitwise)) create two variables with the same type. In code:
__attribute__((bitwise)) unsigned a, b;
__attribute__((bitwise)) unsigned c, d;
typedef __attribute__((bitwise)) unsigned foo_t;
foo_t e, f;
foo_t g, h;
a and b have the same type.
c and d have the same type.
e, f, g, and h have the same type.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c/59852] Support sparse-style __attribute__((bitwise)) (type attribute)
2014-01-17 5:32 [Bug c/59852] New: Support sparse-style __attribute__((bitwise)) (type attribute) 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
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: tromey at gcc dot gnu.org @ 2014-01-20 23:46 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59852
Tom Tromey <tromey at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |tromey at gcc dot gnu.org
--- Comment #2 from Tom Tromey <tromey at gcc dot gnu.org> ---
Suppose 'x' is of bitwise type.
Is "x == x" an allowable operation?
On the one hand, it isn't obvious whether "==" is "strictly bitwise".
On the other hand, this seems well-defined, at least in
cases where no promotion is needed.
This applies to "!=" as well.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c/59852] Support sparse-style __attribute__((bitwise)) (type attribute)
2014-01-17 5:32 [Bug c/59852] New: Support sparse-style __attribute__((bitwise)) (type attribute) 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
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: hpa at zytor dot com @ 2014-01-21 0:00 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59852
--- Comment #3 from H. Peter Anvin <hpa at zytor dot com> ---
a == b and a != b are permitted.
~a is permitted iff sizeof(a) >= sizeof(int).
!a and other booleanizing operations are permitted but produces integer
(non-bitwise) results.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c/59852] Support sparse-style __attribute__((bitwise)) (type attribute)
2014-01-17 5:32 [Bug c/59852] New: Support sparse-style __attribute__((bitwise)) (type attribute) hpa at zytor dot com
` (2 preceding siblings ...)
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
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: josh at joshtriplett dot org @ 2014-01-21 0:39 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59852
--- Comment #4 from Josh Triplett <josh at joshtriplett dot org> ---
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;
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c/59852] Support sparse-style __attribute__((bitwise)) (type attribute)
2014-01-17 5:32 [Bug c/59852] New: Support sparse-style __attribute__((bitwise)) (type attribute) hpa at zytor dot com
` (3 preceding siblings ...)
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
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: tromey at gcc dot gnu.org @ 2014-01-21 2:34 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59852
--- Comment #5 from Tom Tromey <tromey at gcc dot gnu.org> ---
(In reply to Josh Triplett from comment #4)
> Also note that arithmetic operations between a bitwise and a known-zero
> value do not warn.
I'm curious about this too.
If it means that the warnings should be deferred until after
optimization, then it seems like maybe a difficult problem.
On the other extreme, if this just refers to constant expressions,
making this a purely front-end feature, then it seems more tractable.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c/59852] Support sparse-style __attribute__((bitwise)) (type attribute)
2014-01-17 5:32 [Bug c/59852] New: Support sparse-style __attribute__((bitwise)) (type attribute) hpa at zytor dot com
` (4 preceding siblings ...)
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
7 siblings, 0 replies; 9+ messages in thread
From: josh at joshtriplett dot org @ 2014-01-21 2:45 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59852
--- Comment #6 from Josh Triplett <josh at joshtriplett dot org> ---
(In reply to Tom Tromey from comment #5)
> (In reply to Josh Triplett from comment #4)
> > Also note that arithmetic operations between a bitwise and a known-zero
> > value do not warn.
>
> I'm curious about this too.
> If it means that the warnings should be deferred until after
> optimization, then it seems like maybe a difficult problem.
> On the other extreme, if this just refers to constant expressions,
> making this a purely front-end feature, then it seems more tractable.
Sparse does it for constant expressions only, as far as I can tell.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c/59852] Support sparse-style __attribute__((bitwise)) (type attribute)
2014-01-17 5:32 [Bug c/59852] New: Support sparse-style __attribute__((bitwise)) (type attribute) hpa at zytor dot com
` (5 preceding siblings ...)
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
7 siblings, 0 replies; 9+ messages in thread
From: josh at joshtriplett dot org @ 2014-01-21 2:54 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59852
--- Comment #7 from Josh Triplett <josh at joshtriplett dot org> ---
(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".
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c/59852] Support sparse-style __attribute__((bitwise)) (type attribute)
2014-01-17 5:32 [Bug c/59852] New: Support sparse-style __attribute__((bitwise)) (type attribute) hpa at zytor dot com
` (6 preceding siblings ...)
2014-01-21 2:54 ` josh at joshtriplett dot org
@ 2014-01-21 3:08 ` josh at joshtriplett dot org
7 siblings, 0 replies; 9+ messages in thread
From: josh at joshtriplett dot org @ 2014-01-21 3:08 UTC (permalink / raw)
To: gcc-bugs
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.
^ permalink raw reply [flat|nested] 9+ messages in thread