linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
To: linux-sparse@vger.kernel.org
Cc: Ramsay Jones <ramsay@ramsayjones.plus.com>,
	Christopher Li <sparse@chrisli.org>,
	Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Subject: [PATCH 2/5] predefine __INT_MAX__ and friends
Date: Mon, 27 Mar 2017 16:19:15 +0200	[thread overview]
Message-ID: <20170327141918.61151-3-luc.vanoostenryck@gmail.com> (raw)
In-Reply-To: <20170327141918.61151-1-luc.vanoostenryck@gmail.com>

Some tests or some code depends on these macros being predefined
by the compiler.

Predefine them.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 lib.c                                | 23 ++++++++++++++++++-----
 validation/preprocessor/predef-max.c | 18 ++++++++++++++++++
 2 files changed, 36 insertions(+), 5 deletions(-)
 create mode 100644 validation/preprocessor/predef-max.c

diff --git a/lib.c b/lib.c
index 272d2c88a..4e6e6acd6 100644
--- a/lib.c
+++ b/lib.c
@@ -827,15 +827,28 @@ static char **handle_switch(char *arg, char **next)
 	return next;
 }
 
-static void predefined_macros(void)
+static void predefined_sizeof(const char *name, unsigned bits)
 {
-	unsigned long long val;
+	add_pre_buffer("#weak_define __SIZEOF_%s__ %d\n", name, bits/8);
+}
 
+static void predefined_type_size(const char *name, const char *suffix, unsigned bits)
+{
+	unsigned long long max = (1ULL << (bits - 1 )) - 1;
+
+	add_pre_buffer("#weak_define __%s_MAX__ %#llx%s\n", name, max, suffix);
+	predefined_sizeof(name, bits);
+}
+
+static void predefined_macros(void)
+{
 	add_pre_buffer("#define __CHECKER__ 1\n");
 
-	val = (1ULL << (bits_in_long-1)) - 1;
-	add_pre_buffer("#weak_define __LONG_MAX__ %#llxLL\n", val);
-	add_pre_buffer("#weak_define __SIZEOF_POINTER__ %d\n", bits_in_pointer/8);
+	predefined_type_size("INT", "", bits_in_int);
+	predefined_type_size("LONG", "L", bits_in_long);
+	predefined_type_size("LONG_LONG", "LL", bits_in_longlong);
+
+	predefined_sizeof("POINTER", bits_in_pointer);
 }
 
 void declare_builtin_functions(void)
diff --git a/validation/preprocessor/predef-max.c b/validation/preprocessor/predef-max.c
new file mode 100644
index 000000000..ad4b7eaf1
--- /dev/null
+++ b/validation/preprocessor/predef-max.c
@@ -0,0 +1,18 @@
+#define TEST_MAX(X, Z)	if (X != ((~ Z) >> 1))	return 1
+
+int test_max(void)
+{
+	TEST_MAX(__INT_MAX__, 0U);
+	TEST_MAX(__LONG_MAX__, 0UL);
+	TEST_MAX(__LONG_LONG_MAX__, 0ULL);
+
+	return 0;
+}
+
+/*
+ * check-name: predefined __<type>_MAX__
+ * check-command: test-linearize -Wno-decl $file
+ * check-output-ignore
+ *
+ * check-output-contains: ret\\..*\\$0
+ */
-- 
2.12.0


  parent reply	other threads:[~2017-03-27 14:21 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-27 14:19 [PATCH 0/5] fix test cases on 32bit Luc Van Oostenryck
2017-03-27 14:19 ` [PATCH 1/5] fix test for cast to bool on 32bit machines Luc Van Oostenryck
2017-03-27 14:19 ` Luc Van Oostenryck [this message]
2017-03-27 14:19 ` [PATCH 3/5] predefine __SIZEOF_INT__ & friends Luc Van Oostenryck
2017-03-27 14:19 ` [PATCH 4/5] fix test validation/div.c Luc Van Oostenryck
2017-03-27 14:19 ` [PATCH 5/5] do not depends on limits.h to test __CHAR_BIT__ Luc Van Oostenryck
2017-04-01 10:32 ` [GIT PULL] fix test cases on 32bit Luc Van Oostenryck

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=20170327141918.61151-3-luc.vanoostenryck@gmail.com \
    --to=luc.vanoostenryck@gmail.com \
    --cc=linux-sparse@vger.kernel.org \
    --cc=ramsay@ramsayjones.plus.com \
    --cc=sparse@chrisli.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).