From patchwork Mon Mar 27 14:34:03 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: 9646905 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 933D5602C8 for ; Mon, 27 Mar 2017 14:36:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 844FB20007 for ; Mon, 27 Mar 2017 14:36:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7751F2840E; Mon, 27 Mar 2017 14:36:24 +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 3C9D020007 for ; Mon, 27 Mar 2017 14:36:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752623AbdC0OgX (ORCPT ); Mon, 27 Mar 2017 10:36:23 -0400 Received: from mail-wr0-f196.google.com ([209.85.128.196]:36224 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752257AbdC0OgW (ORCPT ); Mon, 27 Mar 2017 10:36:22 -0400 Received: by mail-wr0-f196.google.com with SMTP id u1so13907842wra.3 for ; Mon, 27 Mar 2017 07:36:21 -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=KagzRfqz196JTlk2tgNQUv4RyXxrSJL4KKOceKfzHB0=; b=IWNcdhGaVMccC7NnJW5ZKKykHa5/QAKRqriGgY42RgEP5H0pEiFNUipmfaMY0L83Q6 qYvmJG1G6JGPPIhFmPKrpexcqD4hIBkGM/slle9jyejjgeyZiulyM0fB6xX4rWxw4nAb XsEVl1XsTkGyGCvXCq97ZLCKN4OxDKNGn9TdPCNLwRQMhX2pZvUAMGxucNF3qhmjZ3dL KYPP0iKRUG8rAP8RlJJLn3XNnzcBTSPrcuV58j7nSLpSfv5URsuzlomPk0VOfd8Ya8qP sQXAgd7kB9KJiyqePWxh3jy8QaMn8NMgM+Eu0Gn4TD7eVEXVhADdfCALSraNmcjv5/Zm dJkg== 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=KagzRfqz196JTlk2tgNQUv4RyXxrSJL4KKOceKfzHB0=; b=uNJ3GtIiCESTfjSkPrhq0j9m5Z/Kz2AFI0CT+V4+HHvT+tswQPObxXDyvqCOMP5H1x SNQd7q049uaGumJgVWebMhzXQI6CvADf2VTACDmQH9DUUFPS2o7Ktb9180HOQzHc1T5/ 1LUjcliUAOwQReYGcEyWuk/R2AHbLBW854MdPhiyruOAlYHKY9ln+hNzMgLysdbZVqDl ue1z0hG/mR1CFpML32NzPHtdlE9Dy+hJ5295hMsaavZ0VmbkLldoiCgK2VN0DyxglE0c AiHkH0F8RJqY7dO1bxfNphM66FUB+/vCcJ2KRrakh8kC2mZaQUwHZu/1u63npd7W2qK+ 550A== X-Gm-Message-State: AFeK/H1Qh+tZj/M/qCIWoKO3uWNR76nIFjMJCAriSV8K1on5i/18YpuViYPfPHr7RpbW0Q== X-Received: by 10.223.163.145 with SMTP id l17mr20502721wrb.103.1490625369949; Mon, 27 Mar 2017 07:36:09 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:802:b00:496:ae63:aebb:a034]) by smtp.gmail.com with ESMTPSA id z88sm975496wrb.26.2017.03.27.07.36.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 27 Mar 2017 07:36:09 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Ramsay Jones , Christopher Li , Luc Van Oostenryck Subject: [PATCH v2] fix expansion of integers to floats Date: Mon, 27 Mar 2017 16:34:03 +0200 Message-Id: <20170327143403.62903-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 The test wasn't using is_float_type() and thus missed SYM_NODE->SUM_BASETYPE::fp_type. Fix this by using is_float_type(). Reported-by: Dibyendu Majumdar Signed-off-by: Luc Van Oostenryck --- Changes since v1: - fix the cases on 32-bit machines. expand.c | 3 +- validation/cast-constant-to-float.c | 35 ++++ validation/cast-constants.c | 357 ++++++++++++++++++++++++++++++++++++ 3 files changed, 393 insertions(+), 2 deletions(-) create mode 100644 validation/cast-constant-to-float.c create mode 100644 validation/cast-constants.c diff --git a/expand.c b/expand.c index 11f7255bf..5f908c971 100644 --- a/expand.c +++ b/expand.c @@ -88,8 +88,7 @@ void cast_value(struct expression *expr, struct symbol *newtype, long long value, mask, signmask; long long oldmask, oldsignmask, dropped; - if (newtype->ctype.base_type == &fp_type || - oldtype->ctype.base_type == &fp_type) + if (is_float_type(newtype) || is_float_type(oldtype)) goto Float; // For pointers and integers, we can just move the value around diff --git a/validation/cast-constant-to-float.c b/validation/cast-constant-to-float.c new file mode 100644 index 000000000..86b7ac0f7 --- /dev/null +++ b/validation/cast-constant-to-float.c @@ -0,0 +1,35 @@ +typedef unsigned int uint; +typedef unsigned long ulong; + +double f1(void) { return -1; } +double f2(void) { return (double)-1; } +double f3(void) { return -1.0; } + +/* + * check-name: cast-constant-to-float + * check-command: test-linearize -Wno-decl $file + * + * check-output-start +f1: +.L0: + + set.64 %r1 <- -1.000000 + ret.64 %r1 + + +f2: +.L2: + + set.64 %r3 <- -1.000000 + ret.64 %r3 + + +f3: +.L4: + + set.64 %r5 <- -1.000000 + ret.64 %r5 + + + * check-output-end + */ diff --git a/validation/cast-constants.c b/validation/cast-constants.c new file mode 100644 index 000000000..f47d6fd34 --- /dev/null +++ b/validation/cast-constants.c @@ -0,0 +1,357 @@ +typedef unsigned int uint; +typedef unsigned long ulong; + +static int uint_2_int(void) { return (int)123U; } +static int long_2_int(void) { return (int)123L; } +static int ulong_2_int(void) { return (int)123UL; } +static int vptr_2_int(void) { return (int)((void*)123); } +static int iptr_2_int(void) { return (int)((int*)128); } +static int float_2_int(void) { return (int)1.123F; } +static int double_2_int(void) { return (int)1.123L; } +static uint int_2_uint(void) { return (uint)123; } +static uint long_2_uint(void) { return (uint)123L; } +static uint ulong_2_uint(void) { return (uint)123UL; } +static uint vptr_2_uint(void) { return (uint)((void*)123); } +static uint iptr_2_uint(void) { return (uint)((int*)128); } +static uint float_2_uint(void) { return (uint)1.123F; } +static uint double_2_uint(void) { return (uint)1.123L; } +static long int_2_long(void) { return (long)123; } +static long uint_2_long(void) { return (long)123U; } +static long ulong_2_long(void) { return (long)123UL; } +static long vptr_2_long(void) { return (long)((void*)123); } +static long iptr_2_long(void) { return (long)((int*)128); } +static long float_2_long(void) { return (long)1.123F; } +static long double_2_long(void) { return (long)1.123L; } +static ulong int_2_ulong(void) { return (ulong)123; } +static ulong uint_2_ulong(void) { return (ulong)123U; } +static ulong long_2_ulong(void) { return (ulong)123L; } +static ulong vptr_2_ulong(void) { return (ulong)((void*)123); } +static ulong iptr_2_ulong(void) { return (ulong)((int*)128); } +static ulong float_2_ulong(void) { return (ulong)1.123F; } +static ulong double_2_ulong(void) { return (ulong)1.123L; } +static void * int_2_vptr(void) { return (void *)123; } +static void * uint_2_vptr(void) { return (void *)123U; } +static void * long_2_vptr(void) { return (void *)123L; } +static void * ulong_2_vptr(void) { return (void *)123UL; } +static void * iptr_2_vptr(void) { return (void *)((int*)128); } +static int * int_2_iptr(void) { return (int *)123; } +static int * uint_2_iptr(void) { return (int *)123U; } +static int * long_2_iptr(void) { return (int *)123L; } +static int * ulong_2_iptr(void) { return (int *)123UL; } +static int * vptr_2_iptr(void) { return (int *)((void*)123); } +static float int_2_float(void) { return (float)123; } +static float uint_2_float(void) { return (float)123U; } +static float long_2_float(void) { return (float)123L; } +static float ulong_2_float(void) { return (float)123UL; } +static float double_2_float(void) { return (float)1.123L; } +static double int_2_double(void) { return (double)123; } +static double uint_2_double(void) { return (double)123U; } +static double long_2_double(void) { return (double)123L; } +static double ulong_2_double(void) { return (double)123UL; } +static double float_2_double(void) { return (double)1.123F; } + +/* + * check-name: cast-constants.c + * check-command: test-linearize -m64 $file + * + * check-output-start +uint_2_int: +.L0: + + ret.32 $123 + + +long_2_int: +.L2: + + ret.32 $123 + + +ulong_2_int: +.L4: + + ret.32 $123 + + +vptr_2_int: +.L6: + + ret.32 $123 + + +iptr_2_int: +.L8: + + ret.32 $128 + + +float_2_int: +.L10: + + ret.32 $1 + + +double_2_int: +.L12: + + ret.32 $1 + + +int_2_uint: +.L14: + + ret.32 $123 + + +long_2_uint: +.L16: + + ret.32 $123 + + +ulong_2_uint: +.L18: + + ret.32 $123 + + +vptr_2_uint: +.L20: + + ret.32 $123 + + +iptr_2_uint: +.L22: + + ret.32 $128 + + +float_2_uint: +.L24: + + ret.32 $1 + + +double_2_uint: +.L26: + + ret.32 $1 + + +int_2_long: +.L28: + + ret.64 $123 + + +uint_2_long: +.L30: + + ret.64 $123 + + +ulong_2_long: +.L32: + + ret.64 $123 + + +vptr_2_long: +.L34: + + ret.64 $123 + + +iptr_2_long: +.L36: + + ret.64 $128 + + +float_2_long: +.L38: + + ret.64 $1 + + +double_2_long: +.L40: + + ret.64 $1 + + +int_2_ulong: +.L42: + + ret.64 $123 + + +uint_2_ulong: +.L44: + + ret.64 $123 + + +long_2_ulong: +.L46: + + ret.64 $123 + + +vptr_2_ulong: +.L48: + + ret.64 $123 + + +iptr_2_ulong: +.L50: + + ret.64 $128 + + +float_2_ulong: +.L52: + + ret.64 $1 + + +double_2_ulong: +.L54: + + ret.64 $1 + + +int_2_vptr: +.L56: + + ret.64 $123 + + +uint_2_vptr: +.L58: + + ret.64 $123 + + +long_2_vptr: +.L60: + + ret.64 $123 + + +ulong_2_vptr: +.L62: + + ret.64 $123 + + +iptr_2_vptr: +.L64: + + ret.64 $128 + + +int_2_iptr: +.L66: + + ret.64 $123 + + +uint_2_iptr: +.L68: + + ret.64 $123 + + +long_2_iptr: +.L70: + + ret.64 $123 + + +ulong_2_iptr: +.L72: + + ret.64 $123 + + +vptr_2_iptr: +.L74: + + ret.64 $123 + + +int_2_float: +.L76: + + set.32 %r39 <- 123.000000 + ret.32 %r39 + + +uint_2_float: +.L78: + + set.32 %r41 <- 123.000000 + ret.32 %r41 + + +long_2_float: +.L80: + + set.32 %r43 <- 123.000000 + ret.32 %r43 + + +ulong_2_float: +.L82: + + set.32 %r45 <- 123.000000 + ret.32 %r45 + + +double_2_float: +.L84: + + set.32 %r47 <- 1.123000 + ret.32 %r47 + + +int_2_double: +.L86: + + set.64 %r49 <- 123.000000 + ret.64 %r49 + + +uint_2_double: +.L88: + + set.64 %r51 <- 123.000000 + ret.64 %r51 + + +long_2_double: +.L90: + + set.64 %r53 <- 123.000000 + ret.64 %r53 + + +ulong_2_double: +.L92: + + set.64 %r55 <- 123.000000 + ret.64 %r55 + + +float_2_double: +.L94: + + set.64 %r57 <- 1.123000 + ret.64 %r57 + + + * check-output-end + */