From patchwork Fri Feb 6 12:51:34 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Schmid X-Patchwork-Id: 5874 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n16CpOm0011603 for ; Fri, 6 Feb 2009 12:51:24 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750831AbZBFMvX (ORCPT ); Fri, 6 Feb 2009 07:51:23 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1750722AbZBFMvX (ORCPT ); Fri, 6 Feb 2009 07:51:23 -0500 Received: from mail2.br-automation.com ([213.33.116.61]:52325 "EHLO mail2.br-automation.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750831AbZBFMvW (ORCPT ); Fri, 6 Feb 2009 07:51:22 -0500 X-AuditID: c0a80110-ab1cabb000000e50-87-498c323e5f65 Received: from brsmtp01.br-automation.com (unknown [192.168.1.60]) by mail2.br-automation.com (Symantec Mail Security) with ESMTP id 309344DC002; Fri, 6 Feb 2009 13:51:10 +0100 (CET) In-Reply-To: <70318cbf0902052015i387c5e18w475704b290904e61@mail.gmail.com> To: Christopher Li Cc: christ.li@gmail.com, Josh Triplett , linux-sparse@vger.kernel.org Subject: [PATCH] Fix implicit cast to float (Was:Re: Initializing float variables without type suffix) MIME-Version: 1.0 X-KeepSent: A9A147C1:624E6D79-C1257555:00437599; type=4; name=$KeepSent X-Mailer: Lotus Notes Release 7.0.2 September 26, 2006 Message-ID: From: Thomas Schmid Date: Fri, 6 Feb 2009 13:51:34 +0100 X-MIMETrack: Serialize by Router on BRSMTP01/Eggelsberg/AT/B&R(Release 8.0.2|August 07, 2008) at 06.02.2009 13:52:16, Serialize complete at 06.02.2009 13:52:16 X-Brightmail-Tracker: AAAAAA== Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org christ.li@gmail.com schrieb am 06.02.2009 05:15:37: > cast_to() seems fine. > > In expanding stage, cast_value() did not cast the constant > correctly. You're right, I also noticed this in the meantime. The decision, whether newtype is int_type or fp_type is not made correctly. The following patch seems to work: Fix implicit cast to float Signed-Off-By: Thomas Schmid --- To unsubscribe from this list: send the line "unsubscribe linux-sparse" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Index: sparse/expand.c =================================================================== --- sparse.orig/expand.c 2009-02-06 11:37:17.717913100 +0100 +++ sparse/expand.c 2009-02-06 11:37:34.973482600 +0100 @@ -116,7 +116,7 @@ Int: return; Float: - if (newtype->ctype.base_type != &fp_type) { + if (is_int_type(newtype)) { value = (long long)old->fvalue; expr->type = EXPR_VALUE; expr->taint = 0; @@ -126,7 +126,7 @@ Float: if (oldtype->ctype.base_type != &fp_type) expr->fvalue = (long double)get_longlong(old); else - expr->fvalue = old->value; + expr->fvalue = old->fvalue; if (!(newtype->ctype.modifiers & MOD_LONGLONG)) { if ((newtype->ctype.modifiers & MOD_LONG))