From patchwork Mon Nov 19 20:53:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ramsay Jones X-Patchwork-Id: 10689431 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9C90914BD for ; Mon, 19 Nov 2018 20:53:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8E1FE29631 for ; Mon, 19 Nov 2018 20:53:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 827572A3F3; Mon, 19 Nov 2018 20:53:42 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 179152A4B9 for ; Mon, 19 Nov 2018 20:53:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730838AbeKTHTF (ORCPT ); Tue, 20 Nov 2018 02:19:05 -0500 Received: from avasout04.plus.net ([212.159.14.19]:52919 "EHLO avasout04.plus.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730828AbeKTHTF (ORCPT ); Tue, 20 Nov 2018 02:19:05 -0500 Received: from [10.0.2.15] ([146.198.133.33]) by smtp with ESMTPA id OqY7g9puZYyh2OqY9gYmBT; Mon, 19 Nov 2018 20:53:41 +0000 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.3 cv=MoN8FVSe c=1 sm=1 tr=0 a=VCDsReDbrwk4B7AcQzWGLw==:117 a=VCDsReDbrwk4B7AcQzWGLw==:17 a=IkcTkHD0fZMA:10 a=EBOSESyhAAAA:8 a=acS-LPI_dNyR2nB0v8AA:9 a=QEXdDO2ut3YA:10 a=yJM6EZoI5SlJf8ks9Ge_:22 X-AUTH: ramsayjones@:2500 To: Luc Van Oostenryck Cc: Sparse Mailing-list From: Ramsay Jones Subject: [PATCH 8/9] pre-processor: add some pre-defined macros Message-ID: Date: Mon, 19 Nov 2018 20:53:38 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 Content-Language: en-GB X-CMAE-Envelope: MS4wfM75lHg7gesP8zrP80h1zf7n+3BV94Eaygh/UMHSQh3Alo+DgUZU3kiy/PU9GTKnvCCbUkqiObUwO4Jo3Ub7pDoPwPM2emkhHe8jLv/c1mcJVHKJI082 KUG9S3uO/ABEcPy/w2aIeLAFuR3HMDP++oZEzHFCvdpmXV+xbv+wxrzKSyduOxQbwEriofuV6a08ww== Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Ramsay Jones --- lib.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/lib.c b/lib.c index 23c3d27..08dc299 100644 --- a/lib.c +++ b/lib.c @@ -46,6 +46,8 @@ #include "target.h" #include "version.h" +#define ULL_BITS (__CHAR_BIT__ * sizeof(unsigned long long)) + int verbose, optimize_level, optimize_size, preprocessing; int die_if_error = 0; int has_error = 0; @@ -1161,6 +1163,11 @@ static char **handle_switch(char *arg, char **next) return next; } +static void predefined_type(const char *name, const char *type_str) +{ + add_pre_buffer("#weak_define __%s_TYPE__ %s\n", name, type_str); +} + static void predefined_sizeof(const char *name, unsigned bits) { char buf[32]; @@ -1177,6 +1184,13 @@ static void predefined_width(const char *name, unsigned bits) predefine(buf, 1, "%d", bits); } +static void predefined_umax(const char *name, const char *suffix, unsigned bits) +{ + unsigned long long max = (~0ULL) >> (ULL_BITS - bits); + + add_pre_buffer("#weak_define __%s_MAX__ %#llx%s\n", name, max, suffix); +} + static void predefined_max(const char *name, const char *suffix, unsigned bits) { unsigned long long max = (1ULL << (bits - 1 )) - 1; @@ -1248,6 +1262,53 @@ static void predefined_macros(void) predefined_type_size("LONG", "L", bits_in_long); predefined_type_size("LONG_LONG", "LL", bits_in_longlong); + predefined_max("INT8", "", 8); + predefined_type("INT8", "signed char"); + predefined_max("INT16", "", 16); + predefined_type("INT16", "short int"); + predefined_max("INT32", "", 32); + predefined_type("INT32", "int"); + predefined_umax("UINT8", "", 8); + predefined_type("UINT8", "unsigned char"); + predefined_umax("UINT16", "", 16); + predefined_type("UINT16", "short unsigned int"); + predefined_umax("UINT32", "U", 32); + predefined_type("UINT32", "unsigned int"); + + if (bits_in_pointer == 64) { + predefined_max("INT64", "L", 64); + predefined_type("INT64", "long int"); + predefined_max("INTMAX", "L", 64); + predefined_type("INTMAX", "long int"); + predefined_max("INTPTR", "L", 64); + predefined_type("INTPTR", "long int"); + predefined_max("PTRDIFF", "L", 64); + predefined_type("PTRDIFF", "long int"); + predefined_umax("UINT64", "UL", 64); + predefined_type("UINT64", "long unsigned int"); + predefined_umax("UINTMAX", "UL", 64); + predefined_type("UINTMAX", "long unsigned int"); + predefined_umax("UINTPTR", "UL", 64); + predefined_type("UINTPTR", "long unsigned int"); + predefined_umax("SIZE", "UL", 64); + } else { + predefined_max("INT64", "LL", 64); + predefined_type("INT64", "long long int"); + predefined_max("INTMAX", "LL", 64); + predefined_type("INTMAX", "long long int"); + predefined_max("INTPTR", "", 32); + predefined_type("INTPTR", "int"); + predefined_max("PTRDIFF", "", 32); + predefined_type("PTRDIFF", "int"); + predefined_umax("UINT64", "ULL", 64); + predefined_type("UINT64", "long long unsigned int"); + predefined_umax("UINTMAX", "ULL", 64); + predefined_type("UINTMAX", "long long unsigned int"); + predefined_umax("UINTPTR", "U", 32); + predefined_type("UINTPTR", "unsigned int"); + predefined_umax("SIZE", "U", 32); + } + predefined_sizeof("INT128", 128); predefined_sizeof("SIZE_T", bits_in_pointer);