From patchwork Tue Mar 9 20:29:15 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kamil Dudka X-Patchwork-Id: 84400 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o29KVnCs006874 for ; Tue, 9 Mar 2010 20:31:50 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755016Ab0CIUbt (ORCPT ); Tue, 9 Mar 2010 15:31:49 -0500 Received: from mx1.redhat.com ([209.132.183.28]:47505 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751494Ab0CIUbs (ORCPT ); Tue, 9 Mar 2010 15:31:48 -0500 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o29KUwBo021358 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 9 Mar 2010 15:30:58 -0500 Received: from vpn1-5-47.ams2.redhat.com (vpn1-5-47.ams2.redhat.com [10.36.5.47]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o29KUv5l006579; Tue, 9 Mar 2010 15:30:57 -0500 From: Kamil Dudka To: Pavel Roskin Subject: Re: Sparse crash when mixing int and enum in ternary operator Date: Tue, 9 Mar 2010 21:29:15 +0100 User-Agent: KMail/1.9.10 Cc: Josh Triplett , Christopher Li , linux-sparse@vger.kernel.org References: <1268097872.16227.10.camel@mj> <20100309191551.GB4586@feather> <1268165517.23196.22.camel@mj> In-Reply-To: <1268165517.23196.22.camel@mj> MIME-Version: 1.0 Content-Disposition: inline Message-Id: <201003092129.16118.kdudka@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.16 Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Tue, 09 Mar 2010 20:31:50 +0000 (UTC) --- 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 I need to somehow get over the EXPR_IMPLIED_CAST to dig the original enum_type