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: Linus Torvalds <torvalds@linux-foundation.org>,
	Bart Van Assche <bvanassche@acm.org>,
	Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Subject: [PATCH 1/5] bitwise: add testcases
Date: Mon, 27 Jun 2022 21:05:36 +0200	[thread overview]
Message-ID: <20220627190540.13358-2-luc.vanoostenryck@gmail.com> (raw)
In-Reply-To: <20220627190540.13358-1-luc.vanoostenryck@gmail.com>

Currently bitwise types only support bitwise operations
(&, |, ^ and ~) and the constant 0 (since this value is
invariant for all bitwise operations and endianness conversion).

But the incoming series will relax this a little bit.
So, add a few testcases for it.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 validation/bitwise-cmp.c         | 32 ++++++++++++++++++++++++++++++++
 validation/bitwise-is-signed.c   | 22 ++++++++++++++++++++++
 validation/linear/bitwise-cmps.c | 18 ++++++++++++++++++
 validation/linear/bitwise-cmpu.c | 18 ++++++++++++++++++
 4 files changed, 90 insertions(+)
 create mode 100644 validation/bitwise-cmp.c
 create mode 100644 validation/bitwise-is-signed.c
 create mode 100644 validation/linear/bitwise-cmps.c
 create mode 100644 validation/linear/bitwise-cmpu.c

diff --git a/validation/bitwise-cmp.c b/validation/bitwise-cmp.c
new file mode 100644
index 000000000000..ca12b5e51e8e
--- /dev/null
+++ b/validation/bitwise-cmp.c
@@ -0,0 +1,32 @@
+#define M 0xffffffff
+
+typedef int __attribute__((bitwise)) b32;
+
+static int eq0(b32 x, b32 y)  { return (x == 0); }
+static int eqm(b32 x, b32 y)  { return (x == M); }
+static int eqx(b32 x, b32 y)  { return (x == y); }
+
+static int ne0(b32 x, b32 y)  { return (x != 0); }
+static int nem(b32 x, b32 y)  { return (x != M); }
+static int nex(b32 x, b32 y)  { return (x != y); }
+
+static int lt0(b32 x, b32 y)  { return (x <  0); }
+static int ltm(b32 x, b32 y)  { return (x <  M); }
+static int ltx(b32 x, b32 y)  { return (x <  y); }
+
+static int lte0(b32 x, b32 y) { return (x <= 0); }
+static int ltem(b32 x, b32 y) { return (x <= M); }
+static int ltex(b32 x, b32 y) { return (x <= y); }
+
+static int gte0(b32 x, b32 y) { return (x >= 0); }
+static int gtem(b32 x, b32 y) { return (x >= M); }
+static int gtex(b32 x, b32 y) { return (x >= y); }
+
+static int gt0(b32 x, b32 y)  { return (x >  0); }
+static int gtm(b32 x, b32 y)  { return (x >  M); }
+static int gtx(b32 x, b32 y)  { return (x >  y); }
+
+/*
+ * check-name: bitwise-cmp
+ * check-known-to-fail
+ */
diff --git a/validation/bitwise-is-signed.c b/validation/bitwise-is-signed.c
new file mode 100644
index 000000000000..dd9c147173cd
--- /dev/null
+++ b/validation/bitwise-is-signed.c
@@ -0,0 +1,22 @@
+#define __bitwise __attribute__((bitwise))
+
+#define is_signed_type(type)  (((type)-1) <= 0)
+
+typedef   signed int __bitwise s;
+typedef unsigned int __bitwise u;
+
+int fos(void);
+int fou(void);
+
+
+int fos(void) { return  is_signed_type(s); }
+int fou(void) { return !is_signed_type(u); }
+
+/*
+ * check-name: bitwise-is-signed
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-returns: 1
+ */
diff --git a/validation/linear/bitwise-cmps.c b/validation/linear/bitwise-cmps.c
new file mode 100644
index 000000000000..6122944a42c6
--- /dev/null
+++ b/validation/linear/bitwise-cmps.c
@@ -0,0 +1,18 @@
+typedef   signed int __attribute__((bitwise)) bs32;
+
+static int ltu(bs32 x, bs32 y)  { return (x <  y); }
+static int lteu(bs32 x, bs32 y) { return (x <= y); }
+static int gteu(bs32 x, bs32 y) { return (x >= y); }
+static int gtu(bs32 x, bs32 y)  { return (x >  y); }
+
+/*
+ * check-name: bitwise-cmps
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-excludes: setb\\.
+ * check-output-excludes: setbe\\.
+ * check-output-excludes: setae\\.
+ * check-output-excludes: seta\\.
+ */
diff --git a/validation/linear/bitwise-cmpu.c b/validation/linear/bitwise-cmpu.c
new file mode 100644
index 000000000000..8932436a7764
--- /dev/null
+++ b/validation/linear/bitwise-cmpu.c
@@ -0,0 +1,18 @@
+typedef unsigned int __attribute__((bitwise)) bu32;
+
+static int ltu(bu32 x, bu32 y)  { return (x <  y); }
+static int lteu(bu32 x, bu32 y) { return (x <= y); }
+static int gteu(bu32 x, bu32 y) { return (x >= y); }
+static int gtu(bu32 x, bu32 y)  { return (x >  y); }
+
+/*
+ * check-name: bitwise-cmpu
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-excludes: setlt\\.
+ * check-output-excludes: setlte\\.
+ * check-output-excludes: setgte\\.
+ * check-output-excludes: setgt\\.
+ */
-- 
2.36.1


  reply	other threads:[~2022-06-27 19:05 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20220623180528.3595304-1-bvanassche@acm.org>
     [not found] ` <20220623180528.3595304-52-bvanassche@acm.org>
     [not found]   ` <20220624045613.GA4505@lst.de>
     [not found]     ` <aa044f61-46f0-5f21-9b17-a1bb1ff9c471@acm.org>
     [not found]       ` <20220625092349.GA23530@lst.de>
     [not found]         ` <3eed7994-8de2-324d-c373-b6f4289a2734@acm.org>
2022-06-26  9:58           ` [PATCH 51/51] fs/zonefs: Fix sparse warnings in tracing code Luc Van Oostenryck
2022-06-26 15:42             ` Bart Van Assche
2022-06-26 16:24               ` Luc Van Oostenryck
2022-06-26 16:33             ` Linus Torvalds
2022-06-26 16:50               ` Linus Torvalds
2022-06-26 20:10                 ` Luc Van Oostenryck
2022-06-26 19:44               ` Luc Van Oostenryck
2022-06-27 19:05               ` [PATCH 0/5] allow -1 and compares in bitwise types Luc Van Oostenryck
2022-06-27 19:05                 ` Luc Van Oostenryck [this message]
2022-06-27 19:05                 ` [PATCH 2/5] bitwise: accept all ones as non-restricted value Luc Van Oostenryck
2022-06-27 23:32                   ` Ramsay Jones
2022-06-27 19:05                 ` [PATCH 3/5] bitwise: allow compares for bitwise types Luc Van Oostenryck
2022-06-27 19:20                   ` Linus Torvalds
2022-06-27 23:34                   ` Ramsay Jones
2022-06-27 19:05                 ` [PATCH 4/5] bitwise: do not remove the signedness of " Luc Van Oostenryck
2022-06-27 19:05                 ` [PATCH 5/5] bitwise: early expansion of simple constants Luc Van Oostenryck
2022-06-27 19:14                 ` [PATCH 0/5] allow -1 and compares in bitwise types Linus Torvalds
2022-06-27 19:15                 ` Bart Van Assche

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=20220627190540.13358-2-luc.vanoostenryck@gmail.com \
    --to=luc.vanoostenryck@gmail.com \
    --cc=bvanassche@acm.org \
    --cc=linux-sparse@vger.kernel.org \
    --cc=torvalds@linux-foundation.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).