From patchwork Tue Mar 28 14:18:26 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: 9649807 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 2F177602C8 for ; Tue, 28 Mar 2017 14:27:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1BCB028405 for ; Tue, 28 Mar 2017 14:27:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0F17D28414; Tue, 28 Mar 2017 14:27:46 +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 A88AE28405 for ; Tue, 28 Mar 2017 14:27:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752620AbdC1O1k (ORCPT ); Tue, 28 Mar 2017 10:27:40 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:36450 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752012AbdC1O1j (ORCPT ); Tue, 28 Mar 2017 10:27:39 -0400 Received: by mail-wm0-f65.google.com with SMTP id x124so11500wmf.3 for ; Tue, 28 Mar 2017 07:27:28 -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:in-reply-to:references; bh=5jsnV8nJRDM02OVF1K7MAN4M1IJMFlnUUn3psjQVnF8=; b=tZSVCcEkKVuLZ3mlxWYdcyahoXn7VgxtGmi09uFwX2ds0F0SZ5iQHAFQ5Lk3NSRbLm iNh6HMoAU2D/Dg34Z09+K0qmVWevLsykAYs/U/GsB6DBWJWI636IooeOnoFEQ9LWjiyP 0ilFOvzqJzFC+z0dHYAJUdf+W0RyftGFUb31QAR9skoRvDj+utLlonv3PnKOU0QZU+xo Q8tV5ZVUT6LOew8E74mfn74qQR0Qd7KVYjIR86JoVhXEMjMezj8CNiZn1jd39hTNTuod ONO0UCW/E60aDY04S+C26RiNZ/7QFS9TIrItixjIsWVuYRVe2vPouAPRjJ+YavnpGSxi Z85Q== 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:in-reply-to :references; bh=5jsnV8nJRDM02OVF1K7MAN4M1IJMFlnUUn3psjQVnF8=; b=tMAwxWY+Cxthl7scLTLLwUoPeGKAdii42E6sBY/mgiZA/URau5dRPSxKPgE3HywjPt PFAX+gbs+IG7N4eld7L4uJHYiItEwq8m3fM+63zzejI0EotKGNIfphyt/sSF0rJYKWXz i+j/+1qIUokqNu5EQdinbSUURshmc+5n2sbXrOWAXtQfEfq4L7Rc7jaMFZqJmAmPL62c nadNbbrMURkpvAEnTu68PUTvu7Sc1NpyTTv1z5+hojejC8k4TOI5N3+LzPg46InW706S JQFJE5um71utXpbJMYqjgMwafsTURGsBIRnnpMyxyyDr2DDSOzjcFd5drz9Qg5aAjp66 jkAg== X-Gm-Message-State: AFeK/H1+R9iD/5ZB4OVLkAM7b4JysqV9hfsl0N2FN99aQNn9o2RgrjlbKMY71yT5UFXEMg== X-Received: by 10.28.17.11 with SMTP id 11mr15150993wmr.32.1490710716519; Tue, 28 Mar 2017 07:18:36 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:802:b00:6c75:f12a:2e2b:e57e]) by smtp.gmail.com with ESMTPSA id w93sm1225792wrb.3.2017.03.28.07.18.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Mar 2017 07:18:36 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Christopher Li , Luc Van Oostenryck Subject: [PATCH 1/4] fix linearize_inc_dec() with floats Date: Tue, 28 Mar 2017 16:18:26 +0200 Message-Id: <20170328141829.21421-2-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.12.0 In-Reply-To: <20170328141829.21421-1-luc.vanoostenryck@gmail.com> References: <20170328141829.21421-1-luc.vanoostenryck@gmail.com> 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 Using the pre or post increment or decrement operator on floating-point values mix the addition of a floating-point value with an *integral* constant 1 or -1. Fix this by checking if we're dealing with fp or not and using the proper fp constants (1.0 or -1.0) if it is the case. Signed-off-by: Luc Van Oostenryck --- linearize.c | 18 ++++++++++++++++-- validation/inc-dec-float.c | 13 +++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 validation/inc-dec-float.c diff --git a/linearize.c b/linearize.c index 209bd2bf3..ed649a86a 100644 --- a/linearize.c +++ b/linearize.c @@ -991,6 +991,18 @@ static pseudo_t add_setval(struct entrypoint *ep, struct symbol *ctype, struct e return target; } +static pseudo_t add_setfval(struct entrypoint *ep, struct symbol *ctype, long double fval) +{ + struct instruction *insn = alloc_typed_instruction(OP_SETVAL, ctype); + struct expression *expr = alloc_expression(insn->pos, EXPR_FVALUE); + pseudo_t target = alloc_pseudo(insn); + insn->target = target; + insn->val = expr; + expr->fvalue = fval; + add_one_insn(ep, insn); + return target; +} + static pseudo_t add_symbol_address(struct entrypoint *ep, struct symbol *sym) { struct instruction *insn = alloc_instruction(OP_SYMADDR, bits_in_pointer); @@ -1028,7 +1040,6 @@ static pseudo_t linearize_access(struct entrypoint *ep, struct expression *expr) return value; } -/* FIXME: FP */ static pseudo_t linearize_inc_dec(struct entrypoint *ep, struct expression *expr, int postop) { struct access_data ad = { NULL, }; @@ -1039,7 +1050,10 @@ static pseudo_t linearize_inc_dec(struct entrypoint *ep, struct expression *expr return VOID; old = linearize_load_gen(ep, &ad); - one = value_pseudo(expr->op_value); + if (is_float_type(expr->ctype)) + one = add_setfval(ep, expr->ctype, expr->op_value); + else + one = value_pseudo(expr->op_value); new = add_binary_op(ep, expr->ctype, op, old, one); linearize_store_gen(ep, new, &ad); finish_address_gen(ep, &ad); diff --git a/validation/inc-dec-float.c b/validation/inc-dec-float.c new file mode 100644 index 000000000..3cac8f3ee --- /dev/null +++ b/validation/inc-dec-float.c @@ -0,0 +1,13 @@ +double fincpre(double a) { ++a; return a; } +double fdecpre(double a) { --a; return a; } +double fincpost(double a) { a++; return a; } +double fdecpost(double a) { a--; return a; } + +/* + * check-name: float inc & dec + * check-command: test-linearize -Wno-decl $file + * check-output-ignore + * + * check-output-excludes: \\$1$ + * check-output-excludes: \\$-1$ + */