diff mbox

[RFC] bits_in_bool should be 8

Message ID 1479156643-28563-1-git-send-email-jlayton@redhat.com (mailing list archive)
State Rejected, archived
Headers show

Commit Message

Jeff Layton Nov. 14, 2016, 8:50 p.m. UTC
Given that we're working with byte-addressable machines, each type must
be at least one byte in size or you'd not be able to take a pointer to
it.

Noticed at random when I ran the sample "compile" program in the
sparse source tree vs. a test C program that uses bools. It crashes
without this patch.

Signed-off-by: Jeff Layton <jlayton@redhat.com>
---
 target.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Christopher Li Nov. 15, 2016, 12:23 a.m. UTC | #1
On Tue, Nov 15, 2016 at 4:50 AM, Jeff Layton <jlayton@redhat.com> wrote:
> Given that we're working with byte-addressable machines, each type must
> be at least one byte in size or you'd not be able to take a pointer to
> it.
>
> Noticed at random when I ran the sample "compile" program in the
> sparse source tree vs. a test C program that uses bools. It crashes
> without this patch.

Do you have the test program to crash sparse?

Sparse should handle bool size correctly. The bits_in_bool is
a internal thing for sparse. From sizeof(bool) point of view,
sparse should treat sizeof(bool) as 8 bits. But bool has only
one bit usable value.

Chris
--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Jeff Layton Nov. 15, 2016, 2:27 a.m. UTC | #2
On Tue, 2016-11-15 at 08:23 +0800, Christopher Li wrote:
> On Tue, Nov 15, 2016 at 4:50 AM, Jeff Layton <jlayton@redhat.com> wrote:
> > Given that we're working with byte-addressable machines, each type must
> > be at least one byte in size or you'd not be able to take a pointer to
> > it.
> > 
> > Noticed at random when I ran the sample "compile" program in the
> > sparse source tree vs. a test C program that uses bools. It crashes
> > without this patch.
> 
> Do you have the test program to crash sparse?
> 
> Sparse should handle bool size correctly. The bits_in_bool is
> a internal thing for sparse. From sizeof(bool) point of view,
> sparse should treat sizeof(bool) as 8 bits. But bool has only
> one bit usable value.
> 
> Chris

Attached. This is also the program I was using to track down the
storage_modifiers problem.

To be clear though, sparse doesn't crash here. I happened to run the
"compile" example program that's in the sources against it while poking
at the other problem and noticed that it crashed.

I don't think we really care much about "compile", but it looked like
it might be indicative of a problem in sparse itself.
diff mbox

Patch

diff --git a/target.c b/target.c
index 17b228ae924c..6a535bc0b2d7 100644
--- a/target.c
+++ b/target.c
@@ -14,7 +14,7 @@  int max_alignment = 16;
 /*
  * Integer data types
  */
-int bits_in_bool = 1;
+int bits_in_bool = 8;
 int bits_in_char = 8;
 int bits_in_short = 16;
 int bits_in_int = 32;