aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/evaluate.c
diff options
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2017-05-19 02:30:39 +0200
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2017-05-19 06:51:34 +0200
commit4e5bb8cfb75de82915cd6a17bbc8a9409d2137de (patch)
treedbae91a0fe7fe572e4547cd44a5d77e2c12339c7 /evaluate.c
parent28ba15f4e8ce477726e80b1e22677fe144973b49 (diff)
downloadsparse-dev-4e5bb8cfb75de82915cd6a17bbc8a9409d2137de.tar.gz
avoid warning on explicit 'bool <- restricted' casts
Conversion to bool is special in C since this conversion is essentially the result of the comparison with zero. As such, some operations which are normally unsafe to do with restricted types, like casting to an unrestricted type, are in fact safe to do when converting to bool and issuing a warning in those case is useless, confusing and causes people to add useless casts in the code in order to shut up the warning. Fix this by catching explicit 'bool <- restricted type' casts and not emit a warning like for others casts of restricted type to non-restrictes ones. Based-on-patch-by: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Diffstat (limited to 'evaluate.c')
-rw-r--r--evaluate.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/evaluate.c b/evaluate.c
index 3dc26fc0..6bcccde2 100644
--- a/evaluate.c
+++ b/evaluate.c
@@ -2821,9 +2821,16 @@ static struct symbol *evaluate_cast(struct expression *expr)
if ((class1 & TYPE_RESTRICT) && restricted_value(target, t1))
warning(expr->pos, "cast to %s",
show_typename(t1));
- if (class2 & TYPE_RESTRICT)
- warning(expr->pos, "cast from %s",
- show_typename(t2));
+ if (class2 & TYPE_RESTRICT) {
+ if (t1 == &bool_ctype) {
+ if (class2 & TYPE_FOULED)
+ warning(expr->pos, "%s degrades to integer",
+ show_typename(t2));
+ } else {
+ warning(expr->pos, "cast from %s",
+ show_typename(t2));
+ }
+ }
}
if (t1 == &ulong_ctype)