From: Chris Li <christ.li@gmail.com>
To: Pavel Roskin <proski@gnu.org>
Cc: linux-sparse@vger.kernel.org
Subject: Re: Bogus warning when comparing nocast short variables
Date: Thu, 22 Jul 2010 15:35:01 -0700 [thread overview]
Message-ID: <AANLkTimxVUO9UNbv6rgKgiukDbCTzMeaKEAoVD7FAt1T@mail.gmail.com> (raw)
In-Reply-To: <1279731062.9003.15.camel@mj>
[-- 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;
}
prev parent reply other threads:[~2010-07-22 22:35 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-07-21 16:51 Bogus warning when comparing nocast short variables Pavel Roskin
2010-07-22 22:35 ` Chris Li [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=AANLkTimxVUO9UNbv6rgKgiukDbCTzMeaKEAoVD7FAt1T@mail.gmail.com \
--to=christ.li@gmail.com \
--cc=linux-sparse@vger.kernel.org \
--cc=proski@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).