From patchwork Wed Apr 12 13:21:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 9677507 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 579BF60325 for ; Wed, 12 Apr 2017 13:24:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 472892867A for ; Wed, 12 Apr 2017 13:24:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3BEA52867D; Wed, 12 Apr 2017 13:24:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 89AA82867A for ; Wed, 12 Apr 2017 13:24:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752481AbdDLNYn (ORCPT ); Wed, 12 Apr 2017 09:24:43 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:33957 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752384AbdDLNYm (ORCPT ); Wed, 12 Apr 2017 09:24:42 -0400 Received: by mail-wm0-f66.google.com with SMTP id x75so6398964wma.1 for ; Wed, 12 Apr 2017 06:24:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=r6T9J314eRrI6iR9cOisy7l2vcJCXAmuujzU6gLHAWE=; b=CqL0oFOYv12mLeWXIvjrp7bck3Hs3nc66j5WFVDym8+x0iyEeHbRDCM0WY/B0Y1rNp +jvDJNqxh4ReGVOCXJzT6ooP+G3Rnp9McY3rP37bEkGdy5woyF35W6oj0oFLxG0OSAMW joH9mq4f/kCz5KWYSUr4iqQshdVVOAJXBlJ+PFGHbagnfrkT/EcCWsyuMoFtY3RYgg4a gDc7GEkl7H/crPgXRMXJUP3putge2TUWpRSsQazdP45dD5kFLsmkUT3MnCUygZUbjPiz Rhy073X6NwiF/vBVIodntJZj+ezxgkM46EOzTmY4SUEyaSftfkZ50Ca8+OgXavi/uVoV pn0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=r6T9J314eRrI6iR9cOisy7l2vcJCXAmuujzU6gLHAWE=; b=mSoyCw9cWPFv6VOIlX7RPZla3hX8q35/+4eSEZdgu+rC4rIgOq5jqDEH5yfMTHT2KB LsKvzTgp9OXPCggdPXduvTGMq0y4OL5cDrNjTFXJP47iu0az9aSWJIwVTvGHVvH5RiM0 FyUHXOhr241gKMh2VS4mgq/PItHRjXfq7MvDb0SWV+j1hUbExQQCk1rJzhmkStCP1uP0 g/QMJLcNjt7zRrME7NDb7kbSPXQ/co5DhSBQL/CuY1rdi16YH/196TiQi1gz8s+taXlS vtSptEyWHrg2un906oAbWVrJtT6Gi/qJMXWpdI2LU9BLeMrXH2BTkXg+XDR2leQ+lt4Z pJ6g== X-Gm-Message-State: AN3rC/6Z1YL1r9zo6RIDBtGw8VmV/PGhkJfXhe9MbrgCMqESGJ9Bc6Gu STKizukrpUX2vg== X-Received: by 10.28.92.65 with SMTP id q62mr20976754wmb.139.1492003481111; Wed, 12 Apr 2017 06:24:41 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:8b2:dc00:6c54:829e:388a:2472]) by smtp.gmail.com with ESMTPSA id y66sm25723760wrb.39.2017.04.12.06.24.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 12 Apr 2017 06:24:40 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Christopher Li , Luc Van Oostenryck Subject: [PATCH] fix 'simplification' of float-to-int casts Date: Wed, 12 Apr 2017 15:21:47 +0200 Message-Id: <20170412132147.46876-1-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.12.0 Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Currently, simplify_cast() don't really take floating-points in account and happily simplify away a float-to-int cast if both types have the same size. Fix this by not touching such casts. Signed-off-by: Luc Van Oostenryck --- This patch is available at: git://github.com/lucvoo/sparse.git fix-f2i-casts based on commit: d440a16358aefd718029963bb2261f1deccfddab (fpops) up to commit: 604e7ef9c37100c4ca3dc0b3bee00d114e265684 simplify.c | 4 ++++ validation/cast-kinds.c | 12 ++++++++---- validation/fp2i-cast.c | 30 ++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 validation/fp2i-cast.c diff --git a/simplify.c b/simplify.c index 2286440e0..256a68b22 100644 --- a/simplify.c +++ b/simplify.c @@ -900,6 +900,10 @@ static int simplify_cast(struct instruction *insn) if (is_ptr_type(orig_type) || is_ptr_type(insn->type)) return 0; + /* Keep float-to-int casts */ + if (is_float_type(orig_type) && !is_float_type(insn->type)) + return 0; + orig_size = orig_type->bit_size; size = insn->size; src = insn->src; diff --git a/validation/cast-kinds.c b/validation/cast-kinds.c index 697f9735e..e686c01ea 100644 --- a/validation/cast-kinds.c +++ b/validation/cast-kinds.c @@ -92,7 +92,8 @@ iptr_2_int: float_2_int: .L10: - ret.32 %arg1 + cast.32 %r17 <- (32) %arg1 + ret.32 %r17 double_2_int: @@ -139,7 +140,8 @@ iptr_2_uint: float_2_uint: .L24: - ret.32 %arg1 + cast.32 %r38 <- (32) %arg1 + ret.32 %r38 double_2_uint: @@ -193,7 +195,8 @@ float_2_long: double_2_long: .L40: - ret.64 %arg1 + cast.64 %r62 <- (64) %arg1 + ret.64 %r62 int_2_ulong: @@ -240,7 +243,8 @@ float_2_ulong: double_2_ulong: .L54: - ret.64 %arg1 + cast.64 %r83 <- (64) %arg1 + ret.64 %r83 int_2_vptr: diff --git a/validation/fp2i-cast.c b/validation/fp2i-cast.c new file mode 100644 index 000000000..08f8c9252 --- /dev/null +++ b/validation/fp2i-cast.c @@ -0,0 +1,30 @@ +#if __SIZEOF_INT__ == __SIZEOF_FLOAT__ +typedef signed int si; +typedef unsigned int ui; +#else +#error "no float-sized integer type" +#endif + +#if __SIZEOF_LONG_LONG__ == __SIZEOF_DOUBLE__ +typedef signed long long sl; +typedef unsigned long long ul; +#else +#error "no double-sized integer type" +#endif + +si f2si(float a) { return a; } +ui f2ui(float a) { return a; } +sl f2sl(float a) { return a; } +ul f2ul(float a) { return a; } +si d2si(double a) { return a; } +ui d2ui(double a) { return a; } +sl d2sl(double a) { return a; } +ul d2ul(double a) { return a; } + +/* + * check-name: fp2i cast + * check-command: test-linearize -Wno-decl $file + * + * check-output-ignore + * check-output-pattern-8-times: cast\\. + */