From: Ben Pfaff <blp@nicira.com>
To: Christopher Li <sparse@chrisli.org>
Cc: linux-sparse@vger.kernel.org
Subject: Re: [PATCH] evaluate: Allow sizeof(_Bool) to succeed.
Date: Mon, 9 May 2011 13:49:37 -0700 [thread overview]
Message-ID: <20110509204937.GI2971@nicira.com> (raw)
In-Reply-To: <BANLkTim26gM+WxF+XSjZTVf+sL9xLLtCoA@mail.gmail.com>
On Mon, May 09, 2011 at 01:31:10PM -0700, Christopher Li wrote:
> On Mon, May 9, 2011 at 1:02 PM, Ben Pfaff <blp@nicira.com> wrote:
>
> > Thank you for applying my patch. ?It does work for me, in the sense
> > that I get a warning instead of an error now, but I'm not so happy to
> > get any diagnostic at all. ?Is there some reason why sizeof(_Bool)
> > warrants a warning when, say, sizeof(long) does not? ?After all, both
> > sizes are implementation defined.
>
> Because sizeof(_Bool) is a little bit special compare to sizeof(long).
> In the case of long, all sizeof(long) * 8 bits are use in the actual value.
> But for the _Bool, only the 1 bit is used in the 8 bits size. In other words,
> the _Bool has a special case of the actual bit size is not a multiple of 8.
>
> Sparse has two hats, it is a C compiler front end, and more often it is
> used in the Linux kernel source sanitize checking. Depending on the sizeof
> _Bool sounds a little bit suspicious in the kernel. I would love to the heard
> your actual usage case of the sizeof(_Bool). Why do you care about this
> warning?
I'm a developer on the Open vSwitch project (http://openvswitch.org).
Open vSwitch has both kernel and userspace code. For a long time,
we've been using sparse to sanity-check our kernel code. Now, I'm
adding support for sanity-checking of userspace code using the same
C=1 "make" option as the kernel. (There's a patch series posted
starting at http://openvswitch.org/pipermail/dev/2011-May/008607.html
in case you're really curious.) It's already found some bugs, mostly
due to the ability to mark network byte order types as special through
__attribute__((bitwise)).
This warning (formerly error) is the only sparse warning left in the
build, which is otherwise clean.
The context for the warning is a C file of code generated by database
interface definition language (IDL) bindings. Each of these structs
corresponds to a row in a database table. Here's the simplest struct
in question, for a database table with only two columns, named 'fault'
and 'mpid':
/* Maintenance_Point table. */
struct ovsrec_maintenance_point {
struct ovsdb_idl_row header_;
/* fault column. */
bool *fault;
size_t n_fault;
/* mpid column. */
int64_t mpid;
};
The 'fault' member is 3-valued: a null pointer means that the row has
an empty "fault" column; otherwise it points either to a malloc()'d
true or false value. The warning then crops up in the generated code
for populating this struct, which does something similar to the
following when the "fault" column is nonempty:
row->fault = xmalloc(sizeof *row->fault);
*row->fault = /* value parsed from database row */;
I could change my IDL code generator to do something different for
this case, but I don't see anything actually wrong with it. This
userspace code is not performance-critical or sensitive to memory
usage, so it's not necessary on the face of it to optimize it.
Thanks,
Ben.
next prev parent reply other threads:[~2011-05-09 20:49 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-05-04 23:39 [PATCH] evaluate: Allow sizeof(_Bool) to succeed Ben Pfaff
2011-05-07 20:37 ` Christopher Li
2011-05-09 20:02 ` Ben Pfaff
2011-05-09 20:31 ` Christopher Li
2011-05-09 20:49 ` Ben Pfaff [this message]
2011-05-12 0:09 ` Christopher Li
2011-05-12 20:48 ` Ben Pfaff
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=20110509204937.GI2971@nicira.com \
--to=blp@nicira.com \
--cc=linux-sparse@vger.kernel.org \
--cc=sparse@chrisli.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 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.