Received: by 2002:ac0:aa62:0:0:0:0:0 with SMTP id w31-v6csp270828ima; Thu, 25 Oct 2018 20:19:12 -0700 (PDT) X-Google-Smtp-Source: AJdET5el/TBomB7RT+y5OB5ZdJmwtIad3AoGAO3+26Bb0JaRnRMheTk9wERl9HZEIH0xo2354XIc X-Received: by 2002:a17:902:930b:: with SMTP id bc11-v6mr1850346plb.101.1540523952592; Thu, 25 Oct 2018 20:19:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540523952; cv=none; d=google.com; s=arc-20160816; b=RHurd5M1AAlNuSZw/kA0hT9TT7Ow9WrQuAWW2Jmf2RalmrbAGPEIwuFml+tMoZXWw2 ltxpkm9mJM63y//KzJvDzCFm4CDBSD7h7NPs70NMUGFn37cLXuevwVdkn5gQUrTpGFGi +AjTJPYMukelEyQRtvtWBiPA54vJXDKCeAo9BzgQIuAR65Vqk1uQaVQoEJXSFSbBVLmJ a5pyvM41jJPKFPem1hSPTPjjygZ/DPSrSgWdCIbCV9s9EBhBiyM0UwFRx3lhzbhoOoUR vn9v3CJ1Nyp/GGu7Zdl06WncF8UGUJ27LvIWPI6BszmbqvZvN9nfvxwwFjox6GdxoJn0 97XQ== 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 z20-v6si9775984pfe.245.2018.10.25.20.18.56; Thu, 25 Oct 2018 20:19:12 -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 S1726179AbeJZLw3 (ORCPT + 99 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 Content-Transfer-Encoding: 8bit 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(-) 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; -- 2.19.1