* Re: Bogus warning when comparing nocast short variables
2010-07-21 16:51 Bogus warning when comparing nocast short variables Pavel Roskin
@ 2010-07-22 22:35 ` Chris Li
0 siblings, 0 replies; 2+ messages in thread
From: Chris Li @ 2010-07-22 22:35 UTC (permalink / raw)
To: Pavel Roskin; +Cc: linux-sparse
[-- Attachment #1: Type: text/plain, Size: 682 bytes --]
On Wed, Jul 21, 2010 at 9:51 AM, Pavel Roskin <proski@gnu.org> wrote:
> Hello!
>
> This test file causes a warning:
>
> typedef short __attribute__((nocast)) u16;
> int main(int argc, char **argv)
> {
> u16 i = (u16)argc;
> u16 j = (u16)2;
> return (i == j);
> }
>
> $ sparse test1.c
> test1.c:6:17: warning: implicit cast from nocast type
> test1.c:6:22: warning: implicit cast from nocast type
The warning come from the implicit cast in the compare
expression. It try to cast "i" and "j" into "int" type before the
compare.
The following patch allow the test-inspect to show the cast
expression.
No patch for the fix yet.
Chris
[-- Attachment #2: inspect-cast.patch --]
[-- Type: application/octet-stream, Size: 1480 bytes --]
diff --git a/ast-inspect.c b/ast-inspect.c
index 293334e..5363de3 100644
--- a/ast-inspect.c
+++ b/ast-inspect.c
@@ -66,6 +66,12 @@ void inspect_statement(AstNode *node)
ast_append_child(node, "post_statement:", stmt->iterator_post_statement,
inspect_statement);
break;
+
+ case STMT_RETURN:
+ ast_append_child(node, "ret_value:", stmt->ret_value, inspect_expression);
+ ast_append_child(node, "ret_target:", stmt->ret_target, inspect_symbol);
+ break;
+
default:
break;
}
@@ -109,7 +115,7 @@ void inspect_symbol(AstNode *node)
{
struct symbol *sym = node->ptr;
node->text = g_strdup_printf("%s %s: %s", node->text, symbol_type_name(sym->type),
- show_ident(sym->ident));
+ builtin_typename(sym) ?: show_ident(sym->ident));
ast_append_child(node, "ctype.base_type:", sym->ctype.base_type,inspect_symbol);
switch (sym->type) {
@@ -181,6 +187,18 @@ void inspect_expression(AstNode *node)
ast_append_child(node, "left:", expr->left, inspect_expression);
ast_append_child(node, "right:", expr->right, inspect_expression);
break;
+
+ case EXPR_CAST:
+ case EXPR_FORCE_CAST:
+ case EXPR_IMPLIED_CAST:
+ ast_append_child(node, "cast_type:", expr->cast_type, inspect_symbol);
+ ast_append_child(node, "cast_expression:", expr->cast_expression, inspect_expression);
+ break;
+
+ case EXPR_PREOP:
+ ast_append_child(node, "unop:", expr->unop, inspect_expression);
+ break;
+
default:
break;
}
^ permalink raw reply related [flat|nested] 2+ messages in thread