fix casting to bool
PATCH 1/1 fix casting to bool
Consider the following function.
static _Bool foo(int x) { return x; }Currently sparse emits:
scast.1 %r2 <- (32) %arg1 ret.1 %r2
This is incorrect since bool requires a zero test.
setne.32 %r2 <- %arg1, $0 ret.1 %r2
This patch adds zero testing for bool in cast_to().
Signed-off-by Xi Wang <[email protected]>
--- evaluate.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
evaluate.c +12 -0
@@ -272,6 +272,18 @@ static struct expression * cast_to(struct expression *old, struct symbol *type)if (old->ctype != &null_ctype &&is_same_type (old, type))return old; +/* bool requires a zero test */ +if (is_bool_type (type)) { + expr =alloc_expression (old->pos,EXPR_COMPARE ); + expr->op =SPECIAL_NOTEQUAL ; + expr->ctype = type; + expr->left = old; + expr->right =alloc_expression (old->pos,EXPR_VALUE ); + expr->right->ctype = old->ctype; + expr->right->value =0 ; +return expr; + } +/* * See if we can simplify the op. Move the cast down. */
Signature · 1 line
1.8.1.2
Quoted 9 lines · Xi Wang
Consider the following function.
static _Bool foo(int x) { return x; }Currently sparse emits:
scast.1 %r2 <- (32) %arg1 ret.1 %r2
Quoted 8 lines
This is incorrect since bool requires a zero test.
setne.32 %r2 <- %arg1, $0 ret.1 %r2This patch adds zero testing for bool in
cast_to().Signed-off-by Xi Wang <[email protected]>
Acked-by Pekka Enberg <[email protected]>
Quoted 34 lines
--- evaluate.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)evaluate.c +12
-1@@ -272,6 +272,18 @@ static struct expression * cast_to(struct expression *old, struct symbol *type)if (old->ctype != &null_ctype &&is_same_type (old, type))return old; +/* bool requires a zero test */ +if (is_bool_type (type)) { + expr =alloc_expression (old->pos,EXPR_COMPARE ); + expr->op =SPECIAL_NOTEQUAL ; + expr->ctype = type; + expr->left = old; + expr->right =alloc_expression (old->pos,EXPR_VALUE ); + expr->right->ctype = old->ctype; + expr->right->value =0 ; +return expr; + } +/* * See if we can simplify the op. Move the cast down. */ --1.8.1.2
--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html