From patchwork Fri Oct 26 03:17:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jason A. Donenfeld" X-Patchwork-Id: 149545 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp245294ljp; Thu, 25 Oct 2018 20:17:19 -0700 (PDT) X-Google-Smtp-Source: AJdET5dnXD8ElO1s0RdSHLxa9n9o6zVdHtLUWLBygcvUyk1BK06qhe9oKtR0alJBDETVV8yAgpKZ X-Received: by 2002:a17:902:b197:: with SMTP id s23-v6mr1252621plr.51.1540523839347; Thu, 25 Oct 2018 20:17:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540523839; cv=none; d=google.com; s=arc-20160816; b=Aba8Tkd9WGKMhE7MSrhOF6J0HeSYzHpHt0new7a7eRzK3SujJSItpGeNYkCTsCPzUn VY3jOc7MV2LL/FwqzsZC4NZ2Vr3QFc8tHK6t6dBjPNJj5R2Mg0EOfzWg3MuUjhGMnRX3 c6O7IeW1J8qhCdBow4zbs8ukatCHo0pRjw0LqeshlrrC//Yi3OY1hyYlDl+f/pfyhMYP sMV5Ue1244kra2hGGr5y1LlX9ZlQbGJ4YKrCfqwBB5HdKezwoKbMtzjPeeij/36DEu4H OmLu/qsHavOC0DC5ElnFsPg0K89zbQl53bu1ipK3K9KXWcXq4UH9GgCMkB0mth4FMDuo DjTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=WHi1qNCmxqy7vRxzGeoi0T9CqvHrHn89X3rdjVPCtas=; b=tkEulZVItnpxAb2rf8SPGWK/iwkSPCGjJ7AiXINDqHqSYWF3QW1o5EzC1b6sG9XsIc v5IjU1/y043lFoUGg1XJdJZc6AqEcL37xi7vtynYLict10gGelpf7FVkwav5FJg55EH3 Y3PV+BaIs8Vx6J6r+IFAUJJPU/0D+gVgzc2k7LAvhQ7WCAhIrEjH4mXed+qIjyms2x4p JcmqAn/5cEttgu0vRAMVFb6QP7lqJOjgIqvbL/lUfgzvKpNvPjrTKZadW8yIC6MPCXvj E1JE7rZkEEz8tXR7Go70OS2s1I34iEgWvnU7/xrqSvuRUbb8K2/G4IYD9Bkq/vONpQxs 0ncg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@zx2c4.com header.s=mail header.b=cSThd1DH; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zx2c4.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s17-v6si10074229pgk.140.2018.10.25.20.17.19; Thu, 25 Oct 2018 20:17:19 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@zx2c4.com header.s=mail header.b=cSThd1DH; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zx2c4.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726198AbeJZLw3 (ORCPT + 32 others); Fri, 26 Oct 2018 07:52:29 -0400 Received: from frisell.zx2c4.com ([192.95.5.64]:38281 "EHLO frisell.zx2c4.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725754AbeJZLw3 (ORCPT ); Fri, 26 Oct 2018 07:52:29 -0400 Received: by frisell.zx2c4.com (ZX2C4 Mail Server) with ESMTP id 27168cfd; Fri, 26 Oct 2018 03:14:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=zx2c4.com; h=from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=mail; bh=zH7lmNzbcb4poiRyxY8QYeJLI p8=; b=cSThd1DH5EwXpjo+odukpoJ2qxeBjJgi2FmK/lSFU92gKEfVHBjUkPKIZ Uac0dCylJx0wVswcxAFbQ4OZObZ8Fy0BidVT4ZRbyKD0ARPxgVg7D8qYisdtAWuz ChG7iYPTdnm4KOd2tumo3e5NWErkvrb6iMxm7D5htHDsZm2q2HHHjYirAQ7rbojL WlldcTw4OFnjch44UuGeVrpSzdRaBvtiXIGzjxHO6EF9nmB4TBWLS101CEWjNcwA G1Fuke5YdVJzbQMZLFzEEi5npUtToFH9Nf2+2ErzWfzGVWEDXxkpEMiM9dWFgpCt xRbyAi7sUe+W0UYH/l2/TOM01AwKw== Received: by frisell.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id 776bb1e7 (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256:NO); Fri, 26 Oct 2018 03:14:18 +0000 (UTC) From: "Jason A. Donenfeld" To: linux-sparse@vger.kernel.org, linux-kernel@vger.kernel.org Cc: "Jason A. Donenfeld" Subject: [PATCH sparse] parse: shifting by full number of bits is undefined Date: Fri, 26 Oct 2018 05:17:00 +0200 Message-Id: <20181026031700.12310-1-Jason@zx2c4.com> In-Reply-To: References: MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The type checker wasn't identifying upper bounds for huge unsigned 64-bit numbers, because the right shift turned into a no-op: zx2c4@thinkpad /tmp $ cat sparse.c enum { sparse_does_not_like_this = 0x8000000000000003ULL }; zx2c4@thinkpad /tmp $ sparse sparse.c sparse.c:1:36: warning: cast truncates bits from constant value (8000000000000003 becomes 3) This works around the issue by detecting when we're going to shift by the size of the variable and treat that as always zero. Signed-off-by: Jason A. Donenfeld --- parse.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.19.1 diff --git a/parse.c b/parse.c index 02a55a7..02d0615 100644 --- a/parse.c +++ b/parse.c @@ -788,7 +788,7 @@ static int type_is_ok(struct symbol *type, Num *upper, Num *lower) if (!is_unsigned) shift--; - if (upper->x == 0 && upper->y >> shift) + if (upper->x == 0 && (shift < (sizeof(upper->y) << 3)) && upper->y >> shift) return 0; if (lower->x == 0 || (!is_unsigned && (~lower->y >> shift) == 0)) return 1;