aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2022-06-27 09:35:07 +0200
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2022-06-27 13:57:02 +0200
commitf8f08b3336e380ed1af5f731cc465fe710e64eec (patch)
treeff49f0af62c9ec5f8799243268f98440a859e589
parentbad12ea3413288aae097bc91dbe4ce1226557966 (diff)
downloadsparse-f8f08b3336e380ed1af5f731cc465fe710e64eec.tar.gz
bitwise: accept all ones as non-restricted value
Currently, the only value bitwise types can act on is 0 because the this value is anyway invariant for all bitwise operations and endianness conversions. But, a bit-pattern of all ones has the same properties and is also very often used. So, accept all ones as a valid value for bitwise operations. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r--evaluate.c2
-rw-r--r--validation/bitwise-cast.c13
2 files changed, 14 insertions, 1 deletions
diff --git a/evaluate.c b/evaluate.c
index 61f59ee3..bcbcdf1e 100644
--- a/evaluate.c
+++ b/evaluate.c
@@ -417,7 +417,7 @@ static int restricted_value(struct expression *v, struct symbol *type)
{
if (v->type != EXPR_VALUE)
return 1;
- if (v->value != 0)
+ if (v->value != 0 && v->value != bits_mask(type->bit_size))
return 1;
return 0;
}
diff --git a/validation/bitwise-cast.c b/validation/bitwise-cast.c
index 0583461c..1075a3e9 100644
--- a/validation/bitwise-cast.c
+++ b/validation/bitwise-cast.c
@@ -35,6 +35,19 @@ static __be32 quuy(void)
return (__attribute__((force)) __be32) 1730;
}
+/* Implicit casts of all ones, legal */
+static __be32 foo1(void)
+{
+ __be32 x = 0xffffffff;
+ return x;
+}
+
+/* Explicit cast of all ones, legal */
+static __be32 bar1(void)
+{
+ return (__be32)0xffffffff;
+}
+
/*
* check-name: conversions to bitwise types
* check-command: sparse -Wbitwise $file