Skip to contentSkip to conversation

casting null pointer constant to non-zero address space is always OK

PATCH New Al Viro 1 participant 1 message Oct 1, 2006 Sparse checker

lore
Share & tools
lore

Al Viro

author
#0 lore raw

PATCH 1/7 casting null pointer constant to non-zero address space is always OK

---
 evaluate.c |   13 ++++++++++++-
 1 files changed, 12 insertions(+), 1 deletions(-)
evaluate.c +12 -1
index 0dc05b9..fd29edf 100644
@@ -2126,14 +2126,25 @@ static int get_as(struct symbol *sym)
 static void cast_to_as(struct expression *e, int as)
 {
 	struct expression *v = e->cast_expression;
+	struct symbol *type = v->ctype;
 
 	if (!Wcast_to_address_space)
 		return;
 
+	if (v->type != EXPR_VALUE || v->value)
+		goto out;
+
 	/* cast from constant 0 to pointer is OK */
-	if (v->type == EXPR_VALUE && is_int_type(v->ctype) && !v->value)
+	if (is_int_type(type))
+		return;
+
+	if (type->type == SYM_NODE)
+		type = type->ctype.base_type;
+
+	if (type->type == SYM_PTR && type->ctype.base_type == &void_ctype)
 		return;
 
+out:
 	warning(e->pos, "cast adds address space to expression (<asn:%d>)", as);
 }
 
Signature · 1 line
1.4.2.GIT