All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] sparse: Add GCC pre-defined macros for user-space
@ 2009-08-15 14:57 Pekka Enberg
  2009-08-15 19:36 ` Christopher Li
  0 siblings, 1 reply; 12+ messages in thread
From: Pekka Enberg @ 2009-08-15 14:57 UTC (permalink / raw)
  To: linux-sparse; +Cc: sparse, penberg, torvalds

Sparse prints a lot of warnings like this for user-space projects:

  /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 defining some GCC pre-processor builtins.

Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
---
 ident-list.h  |    7 +++++++
 pre-process.c |   20 ++++++++++++++++++++
 2 files changed, 27 insertions(+), 0 deletions(-)

diff --git a/ident-list.h b/ident-list.h
index 0ee81bc..c0a2735 100644
--- a/ident-list.h
+++ b/ident-list.h
@@ -99,6 +99,13 @@ __IDENT(__func___ident, "__func__", 0);
 __IDENT(__FUNCTION___ident, "__FUNCTION__", 0);
 __IDENT(__PRETTY_FUNCTION___ident, "__PRETTY_FUNCTION__", 0);
 
+__IDENT(__SCHAR_MAX__ident, "__SCHAR_MAX__", 0);
+__IDENT(__SHRT_MAX__ident, "__SHRT_MAX__", 0);
+__IDENT(__INT_MAX__ident, "__INT_MAX__", 0);
+__IDENT(__LONG_MAX__ident, "__LONG_MAX__", 0);
+__IDENT(__LONG_LONG_MAX__ident, "__LONG_LONG_MAX__", 0);
+__IDENT(__WCHAR_MAX__ident, "__WCHAR_MAX__", 0);
+
 /* Sparse commands */
 IDENT_RESERVED(__context__);
 IDENT_RESERVED(__range__);
diff --git a/pre-process.c b/pre-process.c
index 34b21ff..de3d3f1 100644
--- a/pre-process.c
+++ b/pre-process.c
@@ -106,6 +106,14 @@ static void replace_with_integer(struct token *token, unsigned int val)
 	token->number = buf;
 }
 
+static void replace_with_long_long(struct token *token, unsigned long long val)
+{
+	char *buf = __alloc_bytes(20);
+	sprintf(buf, "%llu", val);
+	token_type(token) = TOKEN_NUMBER;
+	token->number = buf;
+}
+
 static struct symbol *lookup_macro(struct ident *ident)
 {
 	struct symbol *sym = lookup_symbol(ident, NS_MACRO | NS_UNDEF);
@@ -167,6 +175,18 @@ static int expand_one_symbol(struct token **list)
 			time(&t);
 		strftime(buffer, 9, "%T", localtime(&t));
 		replace_with_string(token, buffer);
+	} else if (token->ident == &__SHRT_MAX__ident) {
+		replace_with_integer(token, __SHRT_MAX__);
+	} else if (token->ident == &__SCHAR_MAX__ident) {
+		replace_with_integer(token, __SCHAR_MAX__);
+	} else if (token->ident == &__INT_MAX__ident) {
+		replace_with_integer(token, __INT_MAX__);
+	} else if (token->ident == &__LONG_MAX__ident) {
+		replace_with_integer(token, __LONG_MAX__);
+	} else if (token->ident == &__LONG_LONG_MAX__ident) {
+		replace_with_long_long(token, __LONG_LONG_MAX__);
+	} else if (token->ident == &__WCHAR_MAX__ident) {
+		replace_with_integer(token, __WCHAR_MAX__);
 	}
 	return 1;
 }
-- 
1.5.6.3


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

* Re: [PATCH] sparse: Add GCC pre-defined macros for user-space
  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
  0 siblings, 1 reply; 12+ messages in thread
From: Christopher Li @ 2009-08-15 19:36 UTC (permalink / raw)
  To: Pekka Enberg; +Cc: linux-sparse, torvalds

On Sat, Aug 15, 2009 at 7:57 AM, Pekka Enberg<penberg@cs.helsinki.fi> wrote:
> +       } else if (token->ident == &__SHRT_MAX__ident) {
> +               replace_with_integer(token, __SHRT_MAX__);
> +       } else if (token->ident == &__SCHAR_MAX__ident) {
> +               replace_with_integer(token, __SCHAR_MAX__);
> +       } else if (token->ident == &__INT_MAX__ident) {
> +               replace_with_integer(token, __INT_MAX__);
> +       } else if (token->ident == &__LONG_MAX__ident) {
> +               replace_with_integer(token, __LONG_MAX__);
> +       } else if (token->ident == &__LONG_LONG_MAX__ident) {
> +               replace_with_long_long(token, __LONG_LONG_MAX__);
> +       } else if (token->ident == &__WCHAR_MAX__ident) {
> +               replace_with_integer(token, __WCHAR_MAX__);


I am pretty sure that is not the way to do it in sparse.  If you just want
add some sparse builtin defines, it is much better to add them in
create_builtin_streams(). It would be even better to group them in a new
function create_builtin_define():

Some thing like:

add_pre_buffer("#weak_define __INT_MAX__ %d\n", __INT_MAX__);

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

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

* Re: [PATCH] sparse: Add GCC pre-defined macros for user-space
  2009-08-15 19:36 ` Christopher Li
@ 2009-08-15 20:26   ` Pekka Enberg
  2009-08-15 22:36     ` Josh Triplett
  0 siblings, 1 reply; 12+ messages in thread
From: Pekka Enberg @ 2009-08-15 20:26 UTC (permalink / raw)
  To: Christopher Li; +Cc: linux-sparse, torvalds

Hi Chris,

On Sat, 2009-08-15 at 12:36 -0700, Christopher Li wrote:
> On Sat, Aug 15, 2009 at 7:57 AM, Pekka Enberg<penberg@cs.helsinki.fi> wrote:
> > +       } else if (token->ident == &__SHRT_MAX__ident) {
> > +               replace_with_integer(token, __SHRT_MAX__);
> > +       } else if (token->ident == &__SCHAR_MAX__ident) {
> > +               replace_with_integer(token, __SCHAR_MAX__);
> > +       } else if (token->ident == &__INT_MAX__ident) {
> > +               replace_with_integer(token, __INT_MAX__);
> > +       } else if (token->ident == &__LONG_MAX__ident) {
> > +               replace_with_integer(token, __LONG_MAX__);
> > +       } else if (token->ident == &__LONG_LONG_MAX__ident) {
> > +               replace_with_long_long(token, __LONG_LONG_MAX__);
> > +       } else if (token->ident == &__WCHAR_MAX__ident) {
> > +               replace_with_integer(token, __WCHAR_MAX__);
> 
> 
> I am pretty sure that is not the way to do it in sparse.  If you just want
> add some sparse builtin defines, it is much better to add them in
> create_builtin_streams(). It would be even better to group them in a new
> function create_builtin_define():
> 
> Some thing like:
> 
> add_pre_buffer("#weak_define __INT_MAX__ %d\n", __INT_MAX__);

Oh, right, makes sense. I am a total sparse newbie so does something
like this look better (works fine for me)?

			Pekka

From 8e19ea98138dd43a5482519fec6f7488422aff30 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 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/lib.c b/lib.c
index 42affcd..0510ae0 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__ %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__);
 }
 
 static struct symbol_list *sparse_tokenstream(struct token *token)
-- 
1.5.6.3




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

* Re: [PATCH] sparse: Add GCC pre-defined macros for user-space
  2009-08-15 20:26   ` Pekka Enberg
@ 2009-08-15 22:36     ` Josh Triplett
  2009-08-16  7:03       ` Pekka Enberg
  0 siblings, 1 reply; 12+ messages in thread
From: Josh Triplett @ 2009-08-15 22:36 UTC (permalink / raw)
  To: Pekka Enberg; +Cc: Christopher Li, linux-sparse, torvalds

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__);

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.

- Josh Triplett

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

* Re: [PATCH] sparse: Add GCC pre-defined macros for user-space
  2009-08-15 22:36     ` Josh Triplett
@ 2009-08-16  7:03       ` Pekka Enberg
  2009-08-16 10:51         ` Josh Triplett
  0 siblings, 1 reply; 12+ messages in thread
From: Pekka Enberg @ 2009-08-16  7:03 UTC (permalink / raw)
  To: Josh Triplett; +Cc: Christopher Li, linux-sparse, torvalds

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




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

* Re: [PATCH] sparse: Add GCC pre-defined macros for user-space
  2009-08-16  7:03       ` Pekka Enberg
@ 2009-08-16 10:51         ` Josh Triplett
  2009-08-16 11:05           ` Pekka Enberg
  0 siblings, 1 reply; 12+ messages in thread
From: Josh Triplett @ 2009-08-16 10:51 UTC (permalink / raw)
  To: Pekka Enberg; +Cc: Christopher Li, linux-sparse, torvalds

On Sun, Aug 16, 2009 at 10:03:53AM +0300, Pekka Enberg wrote:
> 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.
[...]
> --- 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)
> +

This looks fine, with one minor nit: s/__STRINGIFY/STRINGIFY2/g or
similar.  The C language reserves identifiers containing "__" (C99
"7.1.3 Reserved identifiers").

- Josh Triplett

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

* Re: [PATCH] sparse: Add GCC pre-defined macros for user-space
  2009-08-16 10:51         ` Josh Triplett
@ 2009-08-16 11:05           ` Pekka Enberg
  2009-08-16 12:41             ` Josh Triplett
  0 siblings, 1 reply; 12+ messages in thread
From: Pekka Enberg @ 2009-08-16 11:05 UTC (permalink / raw)
  To: Josh Triplett; +Cc: Christopher Li, linux-sparse, torvalds

Hi Josh,

On Sun, 2009-08-16 at 03:51 -0700, Josh Triplett wrote:
> On Sun, Aug 16, 2009 at 10:03:53AM +0300, Pekka Enberg wrote:
> > 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.
> [...]
> > --- 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)
> > +
> 
> This looks fine, with one minor nit: s/__STRINGIFY/STRINGIFY2/g or
> similar.  The C language reserves identifiers containing "__" (C99
> "7.1.3 Reserved identifiers").

Of course. Here's the final patch. *fingers crossed*

			Pekka

From 8894fa768ddc69f4c7d2160c67e080731aefb88e 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..25abb80 100644
--- a/lib.h
+++ b/lib.h
@@ -17,6 +17,9 @@
 #include "compat.h"
 #include "ptrlist.h"
 
+#define DO_STRINGIFY(x) #x
+#define STRINGIFY(x) DO_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




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

* Re: [PATCH] sparse: Add GCC pre-defined macros for user-space
  2009-08-16 11:05           ` Pekka Enberg
@ 2009-08-16 12:41             ` Josh Triplett
  2009-08-16 17:50               ` Christopher Li
  0 siblings, 1 reply; 12+ messages in thread
From: Josh Triplett @ 2009-08-16 12:41 UTC (permalink / raw)
  To: Pekka Enberg; +Cc: Christopher Li, linux-sparse, torvalds

On Sun, Aug 16, 2009 at 02:05:33PM +0300, Pekka Enberg wrote:
> Of course. Here's the final patch. *fingers crossed*

Looks good to me.

Acked-by: Josh Triplett <josh@joshtriplett.org>

> 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..25abb80 100644
> --- a/lib.h
> +++ b/lib.h
> @@ -17,6 +17,9 @@
>  #include "compat.h"
>  #include "ptrlist.h"
>  
> +#define DO_STRINGIFY(x) #x
> +#define STRINGIFY(x) DO_STRINGIFY(x)
> +
>  extern int verbose, optimize, optimize_size, preprocessing;
>  extern int die_if_error;
>  extern int repeat_phase, merge_phi_sources;

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

* Re: [PATCH] sparse: Add GCC pre-defined macros for user-space
  2009-08-16 12:41             ` Josh Triplett
@ 2009-08-16 17:50               ` Christopher Li
  2009-08-16 18:56                 ` Josh Triplett
  0 siblings, 1 reply; 12+ messages in thread
From: Christopher Li @ 2009-08-16 17:50 UTC (permalink / raw)
  To: Josh Triplett; +Cc: Pekka Enberg, linux-sparse

On Sun, Aug 16, 2009 at 5:41 AM, Josh Triplett<josh@joshtriplett.org> wrote:
> On Sun, Aug 16, 2009 at 02:05:33PM +0300, Pekka Enberg wrote:
>> Of course. Here's the final patch. *fingers crossed*
>
> Looks good to me.
>
> Acked-by: Josh Triplett <josh@joshtriplett.org>
>

Looks good to me too. I will apply.

The linux kernel has a STRING macro. I will rename to match
that if nobody objects.

Chris

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

* Re: [PATCH] sparse: Add GCC pre-defined macros for user-space
  2009-08-16 17:50               ` Christopher Li
@ 2009-08-16 18:56                 ` Josh Triplett
  2009-08-16 19:34                   ` Johannes Berg
  0 siblings, 1 reply; 12+ messages in thread
From: Josh Triplett @ 2009-08-16 18:56 UTC (permalink / raw)
  To: Christopher Li; +Cc: Pekka Enberg, linux-sparse

On Sun, Aug 16, 2009 at 10:50:46AM -0700, Christopher Li wrote:
> On Sun, Aug 16, 2009 at 5:41 AM, Josh Triplett<josh@joshtriplett.org> wrote:
> > On Sun, Aug 16, 2009 at 02:05:33PM +0300, Pekka Enberg wrote:
> >> Of course. Here's the final patch. *fingers crossed*
> >
> > Looks good to me.
> >
> > Acked-by: Josh Triplett <josh@joshtriplett.org>
> >
> 
> Looks good to me too. I will apply.
> 
> The linux kernel has a STRING macro. I will rename to match
> that if nobody objects.

Matching Linux seems sensible, but I don't see that macro in any general
code, just a bunch of local defines with various names.  A few quick
greps on current git master turned up at least:

Documentation/trace/ftrace.txt:#define _STR(x) #x
Documentation/trace/ftrace.txt-#define STR(x) _STR(x)
arch/cris/boot/tools/build.c:#define STRINGIFY(x) #x
arch/cris/include/arch-v10/arch/irq.h:#define __STR(x) #x
arch/cris/include/arch-v10/arch/irq.h-#define STR(x) __STR(x)
arch/cris/include/arch-v32/arch/hwregs/supp_reg.h-#ifndef STRINGIFYFY
arch/cris/include/arch-v32/arch/hwregs/supp_reg.h:#define STRINGIFYFY(i) #i
arch/cris/include/arch-v32/arch/irq.h:#define STR2(x) #x
arch/cris/include/arch-v32/arch/irq.h-#define STR(x) STR2(x)
arch/m68k/include/asm/entry_mm.h-#define STR(X) STR1(X)
arch/m68k/include/asm/entry_mm.h:#define STR1(X) #X
arch/m68k/lib/checksum.c-#define STR(X) STR1(X)
arch/m68k/lib/checksum.c:#define STR1(X) #X
arch/mips/include/asm/mipsregs.h-#ifndef __STR
arch/mips/include/asm/mipsregs.h:#define __STR(x) #x
arch/mips/include/asm/sim.h:#define __str2(x) #x
arch/mips/include/asm/sim.h-#define __str(x) __str2(x)
arch/mips/kernel/unaligned.c-#define STR(x)  __STR(x)
arch/mips/kernel/unaligned.c:#define __STR(x)  #x
arch/powerpc/boot/reg.h:#define __stringify_1(x)        #x
arch/powerpc/boot/reg.h-#define __stringify(x)          __stringify_1(x)
arch/sh/include/cpu-sh5/cpu/registers.h:#define __str(x)  #x
arch/um/drivers/mconsole_user.c:#define STRINGX(x) #x
arch/um/drivers/mconsole_user.c-#define STRING(x) STRINGX(x)
arch/um/sys-i386/shared/sysdep/kernel-offsets.h:#define STR(x) #x
arch/um/sys-x86_64/shared/sysdep/kernel-offsets.h:#define DEFINE_STR1(x) #x
arch/x86/kernel/machine_kexec_32.c:#define __STR(X) #X
arch/x86/kernel/machine_kexec_32.c-#define STR(X) __STR(X)

And probably more.  (Also, the above didn't necessarily capture both macros
from each pair.)

So, I don't see any particular consistency here that we can follow, other than
that the macro should probably have "str" in it somewhere. :)  And if we have
to choose, I think STRINGIFY seems more descriptive than just STRING.

- Josh Triplett

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

* Re: [PATCH] sparse: Add GCC pre-defined macros for user-space
  2009-08-16 18:56                 ` Josh Triplett
@ 2009-08-16 19:34                   ` Johannes Berg
  2009-08-16 20:00                     ` Josh Triplett
  0 siblings, 1 reply; 12+ messages in thread
From: Johannes Berg @ 2009-08-16 19:34 UTC (permalink / raw)
  To: Josh Triplett; +Cc: Christopher Li, Pekka Enberg, linux-sparse

[-- Attachment #1: Type: text/plain, Size: 690 bytes --]

On Sun, 2009-08-16 at 11:56 -0700, Josh Triplett wrote:

> > The linux kernel has a STRING macro. I will rename to match
> > that if nobody objects.
> 
> Matching Linux seems sensible, but I don't see that macro in any general
> code, just a bunch of local defines with various names.  A few quick
> greps on current git master turned up at least:

> So, I don't see any particular consistency here that we can follow, other than
> that the macro should probably have "str" in it somewhere. :)  And if we have
> to choose, I think STRINGIFY seems more descriptive than just STRING.

There's include/linux/stringify.h that all those instances you found
could use.

johannes

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 801 bytes --]

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

* Re: [PATCH] sparse: Add GCC pre-defined macros for user-space
  2009-08-16 19:34                   ` Johannes Berg
@ 2009-08-16 20:00                     ` Josh Triplett
  0 siblings, 0 replies; 12+ messages in thread
From: Josh Triplett @ 2009-08-16 20:00 UTC (permalink / raw)
  To: Johannes Berg; +Cc: Christopher Li, Pekka Enberg, linux-sparse

On Sun, Aug 16, 2009 at 09:34:31PM +0200, Johannes Berg wrote:
> On Sun, 2009-08-16 at 11:56 -0700, Josh Triplett wrote:
> 
> > > The linux kernel has a STRING macro. I will rename to match
> > > that if nobody objects.
> > 
> > Matching Linux seems sensible, but I don't see that macro in any general
> > code, just a bunch of local defines with various names.  A few quick
> > greps on current git master turned up at least:
> 
> > So, I don't see any particular consistency here that we can follow, other than
> > that the macro should probably have "str" in it somewhere. :)  And if we have
> > to choose, I think STRINGIFY seems more descriptive than just STRING.
> 
> There's include/linux/stringify.h that all those instances you found
> could use.

Interesting.  I don't know why my search missed that one.  Unfortunate
that it settled on __stringify, though.

Thanks fo the pointer.

- Josh Triplett

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

end of thread, other threads:[~2009-08-16 20:00 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.