From: Kamil Dudka <kdudka@redhat.com>
To: Christopher Li <sparse@chrisli.org>
Cc: Pavel Roskin <proski@gnu.org>, linux-sparse@vger.kernel.org
Subject: Re: Sparse crash when mixing int and enum in ternary operator
Date: Tue, 9 Mar 2010 14:46:49 +0100 [thread overview]
Message-ID: <201003091446.50092.kdudka@redhat.com> (raw)
In-Reply-To: <70318cbf1003082143n15e88111haee15d2aa027c0b@mail.gmail.com>
[-- Attachment #1: Type: Text/Plain, Size: 838 bytes --]
On Tue March 9 2010 06:43:09 Christopher Li wrote:
> On Mon, Mar 8, 2010 at 5:24 PM, Pavel Roskin <proski@gnu.org> wrote:
> > Hello!
> >
> > Sparse crashed when checking drivers/net/wireless/ath/ath9k/gpio.c in
> > Linux. I could reduce the crash to the following simple program:
> >
> > enum kind {
> > GOOD
> > };
> > static void foo(enum kind k)
> > {
> > }
> > static void bar(int ok, int k)
> > {
> > foo(ok ? GOOD : k);
> > }
>
> Confirm. This is cause by the recent enum-warning patch. Without it the
> sparse runs fine.
Thank both of you for tacking down the bug!
> Let me see if this is some thing easy to fix.
It's easy to fix as soon as I understand how EXPR_CONDITIONAL/EXPR_SELECT
work in sparse. A fix from scratch is attached, but I'll need more time
for testing it and to write some extra test-cases.
Kamil
[-- Attachment #2: sparse-enum.patch --]
[-- Type: text/x-patch, Size: 994 bytes --]
diff --git a/evaluate.c b/evaluate.c
index d3d5e6f..214b2b7 100644
--- a/evaluate.c
+++ b/evaluate.c
@@ -327,13 +327,28 @@ warn_for_int_to_enum_conversion (struct expression *expr, struct symbol *typeb)
}
static void
-warn_for_enum_conversions(struct expression *expr, struct symbol *type)
+do_warn_for_enum_conversions(struct expression *expr, struct symbol *type)
{
warn_for_different_enum_types (expr, type);
warn_for_enum_to_int_conversion (expr, type);
warn_for_int_to_enum_conversion (expr, type);
}
+static void
+warn_for_enum_conversions(struct expression *expr, struct symbol *type)
+{
+ switch (expr->type) {
+ case EXPR_CONDITIONAL:
+ case EXPR_SELECT:
+ do_warn_for_enum_conversions(expr->cond_true, type);
+ do_warn_for_enum_conversions(expr->cond_false, type);
+ break;
+
+ default:
+ do_warn_for_enum_conversions(expr, type);
+ }
+}
+
/*
* This gets called for implicit casts in assignments and
* integer promotion. We often want to try to move the
next prev parent reply other threads:[~2010-03-09 13:48 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-03-09 1:24 Sparse crash when mixing int and enum in ternary operator Pavel Roskin
2010-03-09 5:43 ` Christopher Li
2010-03-09 13:46 ` Kamil Dudka [this message]
2010-03-09 18:26 ` Pavel Roskin
2010-03-09 18:35 ` Pavel Roskin
2010-03-09 19:06 ` Kamil Dudka
2010-03-09 19:15 ` Josh Triplett
2010-03-09 20:11 ` Pavel Roskin
2010-03-09 20:29 ` Kamil Dudka
2010-03-09 23:30 ` Kamil Dudka
2010-03-10 1:09 ` Pavel Roskin
2010-03-10 16:05 ` Kamil Dudka
2010-03-10 20:27 ` Pavel Roskin
2010-03-10 20:44 ` Kamil Dudka
2010-03-10 21:03 ` Kamil Dudka
2010-03-10 21:56 ` Christopher Li
2010-03-13 17:22 ` Kamil Dudka
2010-03-21 15:27 ` Kamil Dudka
2010-03-24 10:07 ` Christopher Li
2010-03-24 10:51 ` Kamil Dudka
2010-03-27 9:16 ` Kamil Dudka
2010-03-27 9:29 ` Josh Triplett
2010-03-27 9:53 ` [PATCH] eliminate insane conversions from int to enum Kamil Dudka
2010-03-29 18:11 ` Christopher Li
2010-03-29 18:05 ` Sparse crash when mixing int and enum in ternary operator Christopher Li
2010-03-29 18:17 ` Kamil Dudka
2010-03-29 18:48 ` Christopher Li
2010-03-29 19:23 ` Kamil Dudka
2010-03-30 5:29 ` Pavel Roskin
2010-03-29 21:26 ` Josh Triplett
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=201003091446.50092.kdudka@redhat.com \
--to=kdudka@redhat.com \
--cc=linux-sparse@vger.kernel.org \
--cc=proski@gnu.org \
--cc=sparse@chrisli.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).