On Tue March 9 2010 06:43:09 Christopher Li wrote: > On Mon, Mar 8, 2010 at 5:24 PM, Pavel Roskin <proski@xxxxxxx> 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
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