http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59852
Bug ID: 59852
Summary: Support sparse-style __attribute__((bitwise)) (type
attribute)
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: enhancement
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: hpa at zytor dot com
The sparse static C language checker contains a type attribute extension:
__attribute__((bitwise))
The bitwise attribute modifies an arithmetic type so that the only arithmetic
options permitted are the ones that are strictly bitwise. This is primarily
used for data items with a specific endianness, such as the "network" side of
the htonX() and ntohX() functions.
The sparse documentation describes this as:
Warn about unsupported operations or type mismatches with
restricted integer types.
Sparse supports an extended attribute, __attribute__((bitwise)),
which creates a new restricted integer type from a base integer type, distinct
from the base integer type and from any
other restricted integer type not declared in the same
declaration or typedef. For example, this allows programs to create typedefs
for integer types with specific endianness. With
-Wbitwise, Sparse will warn on any use of a restricted type in
arithmetic operations other than bitwise operations, and on any conversion of
one restricted type into another, except
via a cast that includes __attribute__((force)).
__bitwise ends up being a "stronger integer separation". That one
doesn't allow you to mix with non-bitwise integers, so now it's much harder to
lose the type by mistake.
__bitwise is for *unique types* that cannot be mixed with
other types, and that you'd never want to just use as a random integer (the
integer 0 is special, though, and gets silently
accepted iirc - it's kind of like "NULL" for pointers). So
"gfp_t" or the "safe endianness" types would be __bitwise: you can only operate
on them by doing specific operations that
know about *that* particular type.
Generally, you want bitwise if you are looking for type safety.
Sparse does not issue these warnings by default.