public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/59852] New: Support sparse-style __attribute__((bitwise)) (type attribute)
@ 2014-01-17  5:32 hpa at zytor dot com
  2014-01-17  9:39 ` [Bug c/59852] " josh at joshtriplett dot org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: hpa at zytor dot com @ 2014-01-17  5:32 UTC (permalink / raw)
  To: gcc-bugs

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.


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2014-01-21  3:08 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
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 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).