linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Al Viro <viro@ftp.linux.org.uk>
To: linux-sparse@vger.kernel.org
Subject: [PATCH] make size_t better approximate the reality
Date: Sun, 1 Jul 2007 08:49:53 +0100	[thread overview]
Message-ID: <20070701074953.GC1101@ftp.linux.org.uk> (raw)

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

             reply	other threads:[~2007-07-01  7:49 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-07-01  7:49 Al Viro [this message]
2007-07-09  2:24 ` [PATCH] make size_t better approximate the reality Josh Triplett

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=20070701074953.GC1101@ftp.linux.org.uk \
    --to=viro@ftp.linux.org.uk \
    --cc=linux-sparse@vger.kernel.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;
as well as URLs for NNTP newsgroup(s).