Linux SPARSE checker discussions
 help / color / mirror / Atom feed
From: Jeff Layton <jeff.layton@primarydata.com>
To: Christopher Li <sparse@chrisli.org>
Cc: Linux-Sparse <linux-sparse@vger.kernel.org>,
	Pekka Enberg <penberg@kernel.org>
Subject: Re: [sparse PATCH RFC] Revert "Revert "sparse: Bump up sizeof(_Bool) to 8 bits""
Date: Tue, 15 Jul 2014 22:23:50 -0400	[thread overview]
Message-ID: <20140715222350.028a7bf6@f20.localdomain> (raw)
In-Reply-To: <CANeU7QnRHvOQHHE2EEWNSUEwFRv66gmHfNXmgZxN+_J7=iPbHg@mail.gmail.com>

On Tue, 15 Jul 2014 12:51:02 -0700
Christopher Li <sparse@chrisli.org> wrote:

> On Tue, Jul 15, 2014 at 8:46 AM, Jeff Layton <jlayton@primarydata.com> wrote:
> >
> >
> > The problem here is that, at least with GCC on x86_64, a _Bool always
> > seems to be end up being 8 bits (which makes sense -- how would you get
> > a pointer to it otherwise?). If you declare and initialize an array like
> > this:
> >
> >     static _Bool boolarray[3] = {
> >             [0] = 1,
> >             [1] = 1,
> >     };
> >
> > ...you get warnings like this (which are bogus):
> >
> >     ./test.c:2:10: warning: Initializer entry defined twice
> >     ./test.c:3:10:   also defined here
> 
> 
> Right.  The bug is in bits_to_bytes(). It round down instead of
> round up. "bits_in_bool" is only a default value. It can be
> reset to other value by the sparse application (sparse as
> library). So the rest of the code still need to coupe with
> it.
> 
>  How about fix bits_to_bytes() to round up:
> 
> diff --git a/target.h b/target.h
> index 1030c7c..140df3c 100644
> --- a/target.h
> +++ b/target.h
> @@ -49,7 +49,7 @@ extern int enum_alignment;
> 
>  static inline int bits_to_bytes(int bits)
>  {
> -       return bits >= 0 ? bits / bits_in_char : -1;
> +       return bits >= 0 ? (bits + bits_in_char - 1) / bits_in_char : -1;
>  }
> 

This makes the bitfield.c validation test fail:

     TEST     bitfield to integer promotion (bitfields.c)
error: actual error text does not match expected error text.
error: see bitfields.c.error.* for further investigation.
--- bitfields.c.error.expected	2014-07-15 22:01:09.236942195 -0400
+++ bitfields.c.error.got	2014-07-15 22:01:09.237942176 -0400
@@ -0,0 +1,2 @@
+bitfields.c:16:19: warning: invalid access past the end of 'y' (0 1)
+bitfields.c:16:19: warning: invalid access past the end of 'y' (0 1)

Though I haven't looked in detail yet as to why it's failing.

> >
> > integer division, and that causes the above bogus warning.
> >
> > Reset it back to 8 bits, and add a validation test that creates the
> > above array to ensure that we don't end up breaking it again.
> 
> The rest of the change looks good. Thanks for the test case.
> 
> My patch is not tested. If you are OK with it, submit a V2
> or I can fix the change for you.
> 
> Thanks
> 
> Chris


-- 
Jeff Layton <jlayton@primarydata.com>

  reply	other threads:[~2014-07-16  2:23 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-15 15:46 [sparse PATCH RFC] Revert "Revert "sparse: Bump up sizeof(_Bool) to 8 bits"" Jeff Layton
2014-07-15 19:51 ` Christopher Li
2014-07-16  2:23   ` Jeff Layton [this message]
2014-07-16  3:21     ` Christopher Li
2014-07-16 16:24       ` Jeff Layton
2014-07-16 21:39         ` Christopher Li

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=20140715222350.028a7bf6@f20.localdomain \
    --to=jeff.layton@primarydata.com \
    --cc=linux-sparse@vger.kernel.org \
    --cc=penberg@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox