From patchwork Sat Jul 21 14:33:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 10538901 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 53292602D7 for ; Sat, 21 Jul 2018 14:33:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E642128C16 for ; Sat, 21 Jul 2018 14:33:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DAC2428C6B; Sat, 21 Jul 2018 14:33:31 +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=-7.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, 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 8A6B028C16 for ; Sat, 21 Jul 2018 14:33:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727867AbeGUP02 (ORCPT ); Sat, 21 Jul 2018 11:26:28 -0400 Received: from mail-ed1-f67.google.com ([209.85.208.67]:33909 "EHLO mail-ed1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727745AbeGUP01 (ORCPT ); Sat, 21 Jul 2018 11:26:27 -0400 Received: by mail-ed1-f67.google.com with SMTP id h1-v6so11989735eds.1 for ; Sat, 21 Jul 2018 07:33:30 -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=tzk+OG3NT3d4krrOIcIIi8MGV41wID/VjErqGoj05kg=; b=p7+i3QAsY4w1jJrnG0sesCtG9uphhFy6L8nszvV6TP8GNdkdL6bPtdaHfmHp2RLR9D tsVskEl8e0zaxZfOFJOuHixLoIBSPoRDQxz59qdTtUqpztrkm9n/pc6I5FCJhmn/VD7K EfvU5vK5M0hzoAk1bl8NvbY5zGULuEnIC4dtuzBViL2ivTYJuFYwNLpmwClSJ58b54Ko Hf8wwTDPR7y6eVdGJCU0iIKCr0fjMk1+33Zy7uVQjXRfFLhMoY2bTXOaZxw3icq1+U76 PIpYSvXsL1eImdsjQt6CF1G+sPOtmnhZqAU/QeuvaPNhXqM7U1R80CZQlLznk7phW4SB U9Ag== 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=tzk+OG3NT3d4krrOIcIIi8MGV41wID/VjErqGoj05kg=; b=rGTSbnMw9s7M+XEHhtqL6AcwKJgzNz6ZVh8A6LXCXV18AlVvgHK5Hf+RwCToT5C0xP JGYmH8OG0fO/95s2n/49aHYPDaz95rgFV76Nq1js8aeTiLXoN/UJEO+Q1QfUQ97vtnTO Th6atp8eVm6zI922bRB0+6b8dXSA+JXE4Pv+v42F5QFyYeJXi9nMDyyhZZTSGCZF7ve5 KngYKJkih4jnrbKj5rJqm+s84ERNLkSSKxTnYhNvKAwul76/zPridnIlxQIOZj8ZT6Yj pe79x5JP9zpXuoMudRPhBOh536QM1GrUs+px7KDwjCBg3/RDvnwwmlN3W1fSwdgGfDeQ dqOg== X-Gm-Message-State: AOUpUlHggvYct7IbCnK/Yl7MWBzFcxWyMMcd/OxBUeeuEAIpAoXagEP/ Fv8Zxo9vpgDD3ukmR9uDEa+HfOcV X-Google-Smtp-Source: AAOMgpcAOEQolzGGdo+yi6rq4k5SqbzXTT9zk/yc3ooCK0vXVqlk0CVdiQAarFPZKF7J4gKvEBTNOg== X-Received: by 2002:a50:8b66:: with SMTP id l93-v6mr6694311edl.44.1532183609234; Sat, 21 Jul 2018 07:33:29 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:4056:df00:e8d8:3f7a:508d:505d]) by smtp.gmail.com with ESMTPSA id j16-v6sm7450230edj.71.2018.07.21.07.33.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 21 Jul 2018 07:33:28 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck Subject: [PATCH 03/17] big-shift: do not evaluate negative or over-sized shifts Date: Sat, 21 Jul 2018 16:33:08 +0200 Message-Id: <20180721143322.99163-4-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180721143322.99163-1-luc.vanoostenryck@gmail.com> References: <20180721143322.99163-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 During simplification, an instruction is evaluated and replaced by its value when all its operands of an instruction are known to be constant. However, for shifts, not all amounts give a well defined result: * when the amount is larger or equal to the type's width * when the shift is negative Thus performing this evaluation can possibly give a different effect than what would happen if the instruction would be executed on the target machine. In one way, this doesn't really matter since it's undefined anyway. But it is desirable for the simplification to be completly deterministic. So, don't perform this evaluation and leave these undefined operations as they are (which still gives the possibility to handle them later, depending on some f-options or maybe in a target-dependent way). Note: this is largely what seems to be done by GCC. Signed-off-by: Luc Van Oostenryck --- simplify.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/simplify.c b/simplify.c index d09ff40ec..0c0f11349 100644 --- a/simplify.c +++ b/simplify.c @@ -472,12 +472,18 @@ static pseudo_t eval_insn(struct instruction *insn) res = left % right; break; case OP_SHL: + if (ur >= size) + goto undef; res = left << right; break; case OP_LSR: + if (ur >= size) + goto undef; res = ul >> ur; break; case OP_ASR: + if (ur >= size) + goto undef; res = left >> right; break; /* Logical */