From patchwork Sun Aug 16 11:05:33 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pekka Enberg X-Patchwork-Id: 41770 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n7GB5mJx021535 for ; Sun, 16 Aug 2009 11:05:48 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753335AbZHPLFe (ORCPT ); Sun, 16 Aug 2009 07:05:34 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1753353AbZHPLFe (ORCPT ); Sun, 16 Aug 2009 07:05:34 -0400 Received: from courier.cs.helsinki.fi ([128.214.9.1]:36991 "EHLO mail.cs.helsinki.fi" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753335AbZHPLFd (ORCPT ); Sun, 16 Aug 2009 07:05:33 -0400 Received: from [213.243.146.249] (cs146249.pp.htv.fi [213.243.146.249]) (AUTH: PLAIN penberg, SSL: TLSv1/SSLv3,256bits,AES256-SHA) by mail.cs.helsinki.fi with esmtp; Sun, 16 Aug 2009 14:05:33 +0300 id 000704C6.4A87E7FD.00004471 Subject: Re: [PATCH] sparse: Add GCC pre-defined macros for user-space From: Pekka Enberg To: Josh Triplett Cc: Christopher Li , linux-sparse@vger.kernel.org, torvalds@linux-foundation.org In-Reply-To: <20090816105114.GA6489@feather> References: <1250348235-19691-1-git-send-email-penberg@cs.helsinki.fi> <70318cbf0908151236q2c691d73n5114ab21f3cbd819@mail.gmail.com> <1250367991.14751.1.camel@penberg-laptop> <20090815223602.GA4516@feather> <1250406233.32343.9.camel@penberg-laptop> <20090816105114.GA6489@feather> Date: Sun, 16 Aug 2009 14:05:33 +0300 Message-Id: <1250420733.9535.1.camel@penberg-laptop> Mime-Version: 1.0 X-Mailer: Evolution 2.24.3 Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org 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 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 Acked-by: Josh Triplett --- 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;