All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/5] fix test cases on 32bit
@ 2017-03-27 14:19 Luc Van Oostenryck
  2017-03-27 14:19 ` [PATCH 1/5] fix test for cast to bool on 32bit machines Luc Van Oostenryck
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Luc Van Oostenryck @ 2017-03-27 14:19 UTC (permalink / raw)
  To: linux-sparse; +Cc: Ramsay Jones, Christopher Li, Luc Van Oostenryck

Some of the test cases made some assumption about the size
of longs or pointers. This serie provides fixes for those.

Luc Van Oostenryck (5):
  fix test for cast to bool on 32bit machines
  predefine __INT_MAX__ and friends
  predefine __SIZEOF_INT__ & friends
  fix test validation/div.c
  do not depends on limits.h to test __CHAR_BIT__

 lib.c                                     | 33 ++++++++++++++++++++++++++-----
 validation/bool-cast-explicit.c           |  2 +-
 validation/bool-cast-implicit.c           |  2 +-
 validation/builtin_char_bit.c             |  7 -------
 validation/div.c                          | 22 +++++++++++----------
 validation/preprocessor/predef-char-bit.c | 16 +++++++++++++++
 validation/preprocessor/predef-max.c      | 18 +++++++++++++++++
 validation/preprocessor/predef-sizeof.c   | 25 +++++++++++++++++++++++
 8 files changed, 101 insertions(+), 24 deletions(-)
 delete mode 100644 validation/builtin_char_bit.c
 create mode 100644 validation/preprocessor/predef-char-bit.c
 create mode 100644 validation/preprocessor/predef-max.c
 create mode 100644 validation/preprocessor/predef-sizeof.c

-- 
2.12.0


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

* [PATCH 1/5] fix test for cast to bool on 32bit machines
  2017-03-27 14:19 [PATCH 0/5] fix test cases on 32bit Luc Van Oostenryck
@ 2017-03-27 14:19 ` Luc Van Oostenryck
  2017-03-27 14:19 ` [PATCH 2/5] predefine __INT_MAX__ and friends Luc Van Oostenryck
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Luc Van Oostenryck @ 2017-03-27 14:19 UTC (permalink / raw)
  To: linux-sparse; +Cc: Ramsay Jones, Christopher Li, Luc Van Oostenryck

The result implicitely depended on longs and/or pointers
being 64 bit or just bigger than ints.

Fix this by running the test with the -m64 flag.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 validation/bool-cast-explicit.c | 2 +-
 validation/bool-cast-implicit.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/validation/bool-cast-explicit.c b/validation/bool-cast-explicit.c
index 6f9c4d461..4e3c2b7ce 100644
--- a/validation/bool-cast-explicit.c
+++ b/validation/bool-cast-explicit.c
@@ -16,7 +16,7 @@ static _Bool fres(le16 a) { return (_Bool)a; }
 
 /*
  * check-name: bool-cast-explicit
- * check-command: test-linearize $file
+ * check-command: test-linearize -m64 $file
  * check-output-ignore
  * check-output-excludes: cast\\.
  *
diff --git a/validation/bool-cast-implicit.c b/validation/bool-cast-implicit.c
index 0e0e69a45..ee8b705b9 100644
--- a/validation/bool-cast-implicit.c
+++ b/validation/bool-cast-implicit.c
@@ -16,7 +16,7 @@ static _Bool fres(le16 a) { return a; }
 
 /*
  * check-name: bool-cast-implicit
- * check-command: test-linearize $file
+ * check-command: test-linearize -m64 $file
  * check-output-ignore
  * check-output-excludes: cast\\.
  *
-- 
2.12.0


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

* [PATCH 2/5] predefine __INT_MAX__ and friends
  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
  2017-03-27 14:19 ` [PATCH 3/5] predefine __SIZEOF_INT__ & friends Luc Van Oostenryck
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Luc Van Oostenryck @ 2017-03-27 14:19 UTC (permalink / raw)
  To: linux-sparse; +Cc: Ramsay Jones, Christopher Li, Luc Van Oostenryck

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


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

* [PATCH 3/5] predefine __SIZEOF_INT__ & friends
  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 ` [PATCH 2/5] predefine __INT_MAX__ and friends Luc Van Oostenryck
@ 2017-03-27 14:19 ` Luc Van Oostenryck
  2017-03-27 14:19 ` [PATCH 4/5] fix test validation/div.c Luc Van Oostenryck
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Luc Van Oostenryck @ 2017-03-27 14:19 UTC (permalink / raw)
  To: linux-sparse; +Cc: Ramsay Jones, Christopher Li, Luc Van Oostenryck

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                                   | 10 ++++++++++
 validation/preprocessor/predef-sizeof.c | 25 +++++++++++++++++++++++++
 2 files changed, 35 insertions(+)
 create mode 100644 validation/preprocessor/predef-sizeof.c

diff --git a/lib.c b/lib.c
index 4e6e6acd6..cf6bea645 100644
--- a/lib.c
+++ b/lib.c
@@ -844,11 +844,21 @@ static void predefined_macros(void)
 {
 	add_pre_buffer("#define __CHECKER__ 1\n");
 
+	predefined_sizeof("SHORT", bits_in_short);
+
 	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("INT128", 128);
+
+	predefined_sizeof("SIZE_T", bits_in_pointer);
+	predefined_sizeof("PTRDIFF_T", bits_in_pointer);
 	predefined_sizeof("POINTER", bits_in_pointer);
+
+	predefined_sizeof("FLOAT", bits_in_float);
+	predefined_sizeof("DOUBLE", bits_in_double);
+	predefined_sizeof("LONG_DOUBLE", bits_in_longdouble);
 }
 
 void declare_builtin_functions(void)
diff --git a/validation/preprocessor/predef-sizeof.c b/validation/preprocessor/predef-sizeof.c
new file mode 100644
index 000000000..12be2dd1d
--- /dev/null
+++ b/validation/preprocessor/predef-sizeof.c
@@ -0,0 +1,25 @@
+#define TEST(X, T)	if (__SIZEOF_ ## X ## __ != sizeof(T))	return 1
+
+int test_sizeof(void)
+{
+	TEST(SHORT, short);
+	TEST(INT, int);
+	TEST(LONG, long);
+	TEST(LONG_LONG, long long);
+	TEST(INT128, __int128);
+	TEST(SIZE_T, __SIZE_TYPE__);
+	TEST(POINTER, void*);
+	TEST(FLOAT, float);
+	TEST(DOUBLE, double);
+	TEST(LONG_DOUBLE, long double);
+
+	return 0;
+}
+
+/*
+ * check-name: predefined __SIZEOF_<type>__
+ * check-command: test-linearize -Wno-decl $file
+ * check-output-ignore
+ *
+ * check-output-contains: ret\\..*\\$0
+ */
-- 
2.12.0


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

* [PATCH 4/5] fix test validation/div.c
  2017-03-27 14:19 [PATCH 0/5] fix test cases on 32bit Luc Van Oostenryck
                   ` (2 preceding siblings ...)
  2017-03-27 14:19 ` [PATCH 3/5] predefine __SIZEOF_INT__ & friends Luc Van Oostenryck
@ 2017-03-27 14:19 ` 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
  5 siblings, 0 replies; 7+ messages in thread
From: Luc Van Oostenryck @ 2017-03-27 14:19 UTC (permalink / raw)
  To: linux-sparse; +Cc: Ramsay Jones, Christopher Li, Luc Van Oostenryck

This test, which test the diagnostics given at the boundary
conditions of division, depends on the header <limits.h> which
itself depends on some macros being defined by the compiler.

Now these macros are predefined (at least the obvious ones)
but it's annoying for the tests to depends on external things
like this header.

Remove this dependence by rewriting the test to use the predefined
macros directly.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 validation/div.c | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/validation/div.c b/validation/div.c
index 3dcbfd57c..3e6fb6988 100644
--- a/validation/div.c
+++ b/validation/div.c
@@ -1,4 +1,6 @@
-#include <limits.h>
+#define	INT_MIN		(-__INT_MAX__ - 1)
+#define	LONG_MIN	(-__LONG_MAX__ - 1)
+#define	LLONG_MIN	(-__LONG_LONG_MAX__ - 1)
 
 static int xd = 1 / 0;
 static int xl = 1L / 0;
@@ -16,14 +18,14 @@ static long long zll = LLONG_MIN % -1;
  * check-name: division constants
  *
  * check-error-start
-div.c:3:19: warning: division by zero
-div.c:4:20: warning: division by zero
-div.c:5:22: warning: division by zero
-div.c:7:25: warning: constant integer operation overflow
-div.c:8:27: warning: constant integer operation overflow
-div.c:9:34: warning: constant integer operation overflow
-div.c:11:25: warning: constant integer operation overflow
-div.c:12:27: warning: constant integer operation overflow
-div.c:13:34: warning: constant integer operation overflow
+div.c:5:19: warning: division by zero
+div.c:6:20: warning: division by zero
+div.c:7:22: warning: division by zero
+div.c:9:25: warning: constant integer operation overflow
+div.c:10:27: warning: constant integer operation overflow
+div.c:11:34: warning: constant integer operation overflow
+div.c:13:25: warning: constant integer operation overflow
+div.c:14:27: warning: constant integer operation overflow
+div.c:15:34: warning: constant integer operation overflow
  * check-error-end
  */
-- 
2.12.0


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

* [PATCH 5/5] do not depends on limits.h to test __CHAR_BIT__
  2017-03-27 14:19 [PATCH 0/5] fix test cases on 32bit Luc Van Oostenryck
                   ` (3 preceding siblings ...)
  2017-03-27 14:19 ` [PATCH 4/5] fix test validation/div.c Luc Van Oostenryck
@ 2017-03-27 14:19 ` Luc Van Oostenryck
  2017-04-01 10:32 ` [GIT PULL] fix test cases on 32bit Luc Van Oostenryck
  5 siblings, 0 replies; 7+ messages in thread
From: Luc Van Oostenryck @ 2017-03-27 14:19 UTC (permalink / raw)
  To: linux-sparse; +Cc: Ramsay Jones, Christopher Li, Luc Van Oostenryck

This test depends on the header <limits.h> which itself depends
on some macros being defined by the compiler.

Now these macros are predefined (at least the obvious ones)
but it's annoying for the tests to depends on external things
like this header.

Remove this dependence by rewriting the test to use the predefined
macros directly.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 validation/builtin_char_bit.c             |  7 -------
 validation/preprocessor/predef-char-bit.c | 16 ++++++++++++++++
 2 files changed, 16 insertions(+), 7 deletions(-)
 delete mode 100644 validation/builtin_char_bit.c
 create mode 100644 validation/preprocessor/predef-char-bit.c

diff --git a/validation/builtin_char_bit.c b/validation/builtin_char_bit.c
deleted file mode 100644
index 30e6bed46..000000000
--- a/validation/builtin_char_bit.c
+++ /dev/null
@@ -1,7 +0,0 @@
-#include <limits.h>
-
-static unsigned int word_bits = sizeof(unsigned int) * CHAR_BIT;
-
-/*
- * check-name: __CHAR_BIT__
- */
diff --git a/validation/preprocessor/predef-char-bit.c b/validation/preprocessor/predef-char-bit.c
new file mode 100644
index 000000000..fed0166e4
--- /dev/null
+++ b/validation/preprocessor/predef-char-bit.c
@@ -0,0 +1,16 @@
+#define TEST_BIT(X, T)	if (__ ## X ## _BIT__  != 8 * sizeof(T)) return 1
+
+int test(void)
+{
+	TEST_BIT(CHAR, char);
+
+	return 0;
+}
+
+/*
+ * check-name: predefined __<type>_BIT__
+ * check-command: test-linearize -Wno-decl $file
+ * check-output-ignore
+ *
+ * check-output-contains: ret\\..*\\$0
+ */
-- 
2.12.0


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

* [GIT PULL] fix test cases on 32bit
  2017-03-27 14:19 [PATCH 0/5] fix test cases on 32bit Luc Van Oostenryck
                   ` (4 preceding siblings ...)
  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 ` Luc Van Oostenryck
  5 siblings, 0 replies; 7+ messages in thread
From: Luc Van Oostenryck @ 2017-04-01 10:32 UTC (permalink / raw)
  To: linux-sparse; +Cc: Christopher Li

This series is available at:
	git://github.com/lucvoo/sparse.git fix-32bit-tests
based on commit:
	97ebb345943918a0688b62cbc9bf878de01ccba4 (sparse-next-2017-03-07)
up to commit:
	c1a53a868ebafd1d134e4a77c86074b9d07e4281


-- Luc Van Oostenryck

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

end of thread, other threads:[~2017-04-01 10:32 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH 2/5] predefine __INT_MAX__ and friends Luc Van Oostenryck
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

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.