diff mbox

Sparse crash when mixing int and enum in ternary operator

Message ID 201003092129.16118.kdudka@redhat.com (mailing list archive)
State Rejected, archived
Headers show

Commit Message

Kamil Dudka March 9, 2010, 8:29 p.m. UTC
None
diff mbox

Patch

--- a/evaluate.c
+++ b/evaluate.c
@@ -327,13 +327,35 @@  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)
 {
+       if (!expr || !type)
+               /* do not crash when there is nothing to check */
+               return;
+
        warn_for_different_enum_types (expr, type);
        warn_for_enum_to_int_conversion (expr, type);
        warn_for_int_to_enum_conversion (expr, type);
 }

> At least I was able to run sparse on the whole kernel (wireless-testing,
> which is based on 2.6.34-rc1) without crashing or reporting anything
> strange.
>
> Actually, omitting the false conditional appears to be invalid.

Unfortunately it's not that easy.  I am still getting a non-sense warning for:

static void foo(void)
{
    enum { VAL } y, x = VAL;
    y = x ?: VAL;
}

$ ./sparse enum.c
enum.c:4:9: warning: conversion of
enum.c:4:9:     int to
enum.c:4:9:     int enum <noident>

I need to somehow get over the EXPR_IMPLIED_CAST to dig the original enum_type