diff options
author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2022-06-27 10:09:04 +0200 |
---|---|---|
committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2022-06-27 13:51:15 +0200 |
commit | bad12ea3413288aae097bc91dbe4ce1226557966 (patch) | |
tree | b99c0df4e6e0616fdc15dc57f3b1a53b49021ef5 | |
parent | 4880bd1999feb9276faacd9a79647b53b6ffe8be (diff) | |
download | sparse-bad12ea3413288aae097bc91dbe4ce1226557966.tar.gz |
bitwise: add testcases
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>
-rw-r--r-- | validation/bitwise-cmp.c | 32 | ||||
-rw-r--r-- | validation/bitwise-is-signed.c | 22 | ||||
-rw-r--r-- | validation/linear/bitwise-cmps.c | 18 | ||||
-rw-r--r-- | validation/linear/bitwise-cmpu.c | 18 |
4 files changed, 90 insertions, 0 deletions
diff --git a/validation/bitwise-cmp.c b/validation/bitwise-cmp.c new file mode 100644 index 00000000..ca12b5e5 --- /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 00000000..dd9c1471 --- /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 00000000..6122944a --- /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 00000000..8932436a --- /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\\. + */ |