linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] make size_t better approximate the reality
@ 2007-07-01  7:49 Al Viro
  2007-07-09  2:24 ` Josh Triplett
  0 siblings, 1 reply; 2+ messages in thread
From: Al Viro @ 2007-07-01  7:49 UTC (permalink / raw)
  To: linux-sparse

From: Al Viro <viro@zeniv.linux.org.uk>
Date: Tue, 26 Jun 2007 17:41:27 -0400
Subject: [PATCH] make size_t better approximate the reality

Instead of "always unsigned long" go for "unsigned int unless
-m64 is given, unsigned long otherwise".  Add an option (-msize-long)
forcing to unsigned long regardless.  Make __SIZE_TYPE__ expansion
match that.

The thing is, addition of checks on comparisons make for very unhappy
min() on (kernel) size_t and sizeof(something) on the targets where
the former is unsigned int.  Which is to say, more than half of them...
AFAICS, the only place needing explicit -msize-long in CHECK_FLAGS
is s390 (it's using unsigned long both for 31- and 64-bit).

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
---
 lib.c    |   10 +++++++++-
 target.c |    4 ++--
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/lib.c b/lib.c
index 7fea474..efba3d4 100644
--- a/lib.c
+++ b/lib.c
@@ -325,6 +325,11 @@ static char **handle_switch_m(char *arg, char **next)
 		max_int_alignment = 8;
 		bits_in_pointer = 64;
 		pointer_alignment = 8;
+		size_t_ctype = &ulong_ctype;
+		ssize_t_ctype = &long_ctype;
+	} else if (!strcmp(arg, "msize-long")) {
+		size_t_ctype = &ulong_ctype;
+		ssize_t_ctype = &long_ctype;
 	}
 	return next;
 }
@@ -599,7 +604,10 @@ void create_builtin_stream(void)
 	// it is "long unsigned int".  In either case we can probably
 	// get away with this.  We need the #weak_define as cgcc will define
 	// the right __SIZE_TYPE__.
-	add_pre_buffer("#weak_define __SIZE_TYPE__ long unsigned int\n");
+	if (size_t_ctype == &ulong_ctype)
+		add_pre_buffer("#weak_define __SIZE_TYPE__ long unsigned int\n");
+	else
+		add_pre_buffer("#weak_define __SIZE_TYPE__ unsigned int\n");
 	add_pre_buffer("#weak_define __STDC__ 1\n");
 
 	add_pre_buffer("#define __builtin_stdarg_start(a,b) ((a) = (__builtin_va_list)(&(b)))\n");
diff --git a/target.c b/target.c
index 22e948e..bf1bb8f 100644
--- a/target.c
+++ b/target.c
@@ -3,8 +3,8 @@
 #include "symbol.h"
 #include "target.h"
 
-struct symbol *size_t_ctype = &ulong_ctype;
-struct symbol *ssize_t_ctype = &long_ctype;
+struct symbol *size_t_ctype = &uint_ctype;
+struct symbol *ssize_t_ctype = &int_ctype;
 
 /*
  * For "__attribute__((aligned))"
-- 
1.5.0-rc2.GIT

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

end of thread, other threads:[~2007-07-09  2:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-07-01  7:49 [PATCH] make size_t better approximate the reality Al Viro
2007-07-09  2:24 ` Josh Triplett

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 NNTP newsgroup(s).