linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pekka Enberg <penberg@cs.helsinki.fi>
To: Josh Triplett <josh@joshtriplett.org>
Cc: Christopher Li <sparse@chrisli.org>,
	linux-sparse@vger.kernel.org, torvalds@linux-foundation.org
Subject: Re: [PATCH] sparse: Add GCC pre-defined macros for user-space
Date: Sun, 16 Aug 2009 10:03:53 +0300	[thread overview]
Message-ID: <1250406233.32343.9.camel@penberg-laptop> (raw)
In-Reply-To: <20090815223602.GA4516@feather>

Hi Josh,

On Sat, Aug 15, 2009 at 11:26:31PM +0300, Pekka Enberg wrote:
> > --- a/lib.c
> > +++ b/lib.c
> > @@ -788,6 +788,14 @@ void create_builtin_stream(void)
> >  		add_pre_buffer("#define __OPTIMIZE__ 1\n");
> >  	if (optimize_size)
> >  		add_pre_buffer("#define __OPTIMIZE_SIZE__ 1\n");
> > +
> > +	/* GCC defines these for limits.h */
> > +	add_pre_buffer("#weak_define __SHRT_MAX__ %d\n", __SHRT_MAX__);
> > +	add_pre_buffer("#weak_define __SCHAR_MAX__ %d\n", __SCHAR_MAX__);
> > +	add_pre_buffer("#weak_define __INT_MAX__ %d\n", __INT_MAX__);
> > +	add_pre_buffer("#weak_define __LONG_MAX__ %ld\n", __LONG_MAX__);
> > +	add_pre_buffer("#weak_define __LONG_LONG_MAX__ %lld\n", __LONG_LONG_MAX__);
> > +	add_pre_buffer("#weak_define __WCHAR_MAX__ %d\n", __WCHAR_MAX__);

On Sat, 2009-08-15 at 15:36 -0700, Josh Triplett wrote:
> These defines need to have the right type suffixes.  GCC defines
> __LONG_LONG_MAX__ with an LL suffix, and __LONG_MAX__ with an L suffix.
> You could either add the appropriate suffixes, or better yet, stringize
> the constants and print them as strings.

Right. Is there a macro in sparse to do the stringification? I didn't
find one and the best I could come up is this.

Thanks for the help so far!

			Pekka

From c96297f4e246f6ba052c99edde3475daa19686a4 Mon Sep 17 00:00:00 2001
From: Pekka Enberg <penberg@cs.helsinki.fi>
Date: Sat, 15 Aug 2009 23:22:24 +0300
Subject: [PATCH] Define GCC builtin defines for limits.h

Sparse produces a bunch of warnings like this when compiling against
glibc:

  /usr/lib/gcc/i486-linux-gnu/4.3.2//include-fixed/limits.h:33:22: warning: undefined preprocessor identifier '__INT_MAX__'
  /usr/lib/gcc/i486-linux-gnu/4.3.2//include-fixed/limits.h:64:5: warning: undefined preprocessor identifier '__SHRT_MAX__'
  /usr/lib/gcc/i486-linux-gnu/4.3.2//include-fixed/limits.h:64:21: warning: undefined preprocessor identifier '__INT_MAX__'
  /usr/include/bits/xopen_lim.h:95:6: warning: undefined preprocessor identifier '__INT_MAX__'
  /usr/include/bits/xopen_lim.h:98:7: warning: undefined preprocessor identifier '__INT_MAX__'

Fix that up by adding some add_pre_buffer() calls to
create_builtin_define(). For future reference, GCC defines the builtins
in the c_cpp_builtins() function in gcc/c-cppbuiltin.c.

Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
---
 lib.c |    8 ++++++++
 lib.h |    3 +++
 2 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/lib.c b/lib.c
index 42affcd..fb7e9bc 100644
--- a/lib.c
+++ b/lib.c
@@ -788,6 +788,14 @@ void create_builtin_stream(void)
 		add_pre_buffer("#define __OPTIMIZE__ 1\n");
 	if (optimize_size)
 		add_pre_buffer("#define __OPTIMIZE_SIZE__ 1\n");
+
+	/* GCC defines these for limits.h */
+	add_pre_buffer("#weak_define __SHRT_MAX__ " STRINGIFY(__SHRT_MAX__) "\n");
+	add_pre_buffer("#weak_define __SCHAR_MAX__ " STRINGIFY(__SCHAR_MAX__) "\n");
+	add_pre_buffer("#weak_define __INT_MAX__ " STRINGIFY(__INT_MAX__) "\n");
+	add_pre_buffer("#weak_define __LONG_MAX__ " STRINGIFY(__LONG_MAX__) "\n");
+	add_pre_buffer("#weak_define __LONG_LONG_MAX__ " STRINGIFY(__LONG_LONG_MAX__) "\n");
+	add_pre_buffer("#weak_define __WCHAR_MAX__ " STRINGIFY(__WCHAR_MAX__) "\n");
 }
 
 static struct symbol_list *sparse_tokenstream(struct token *token)
diff --git a/lib.h b/lib.h
index b22fa93..62f7433 100644
--- a/lib.h
+++ b/lib.h
@@ -17,6 +17,9 @@
 #include "compat.h"
 #include "ptrlist.h"
 
+#define __STRINGIFY(x) #x
+#define STRINGIFY(x) __STRINGIFY(x)
+
 extern int verbose, optimize, optimize_size, preprocessing;
 extern int die_if_error;
 extern int repeat_phase, merge_phi_sources;
-- 
1.5.6.3




  reply	other threads:[~2009-08-16  7:03 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-15 14:57 [PATCH] sparse: Add GCC pre-defined macros for user-space Pekka Enberg
2009-08-15 19:36 ` Christopher Li
2009-08-15 20:26   ` Pekka Enberg
2009-08-15 22:36     ` Josh Triplett
2009-08-16  7:03       ` Pekka Enberg [this message]
2009-08-16 10:51         ` Josh Triplett
2009-08-16 11:05           ` Pekka Enberg
2009-08-16 12:41             ` Josh Triplett
2009-08-16 17:50               ` Christopher Li
2009-08-16 18:56                 ` Josh Triplett
2009-08-16 19:34                   ` Johannes Berg
2009-08-16 20:00                     ` 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=1250406233.32343.9.camel@penberg-laptop \
    --to=penberg@cs.helsinki.fi \
    --cc=josh@joshtriplett.org \
    --cc=linux-sparse@vger.kernel.org \
    --cc=sparse@chrisli.org \
    --cc=torvalds@linux-foundation.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).