From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BF3563314BC for ; Mon, 22 Dec 2025 17:15:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.46 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766423703; cv=none; b=eOvrFtgbbTxqXwF/0Qsj5HPFbFA0inZACizBRnyK3VW9TEPhZd7oj5dFSrDc0m4HCR1Sg1McSnE2p+g6Pn2nuQOM0XTVmHodMU5vQ3znN4JrIjC606g/mpaMxPR9BGinA+qCNTOken0VbMOoqxbEX6x2gLpFkqJH6GhFkku4DZc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766423703; c=relaxed/simple; bh=CcddaCi3sYjcygd9mvn6PRNkI8gX+uLIVjXxPooFXok=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=OVaKnKKL+OgYlpO6mlLQUNDdUotp7zdm27DqIO+uJP42jmy0bGJ/TYvSqGzvY7Dfs5YvpQpLOCVkKosJhgJTWrgtBEMu/7qA/v23N8XDp6QPbB8XWe0f1vlcWVFLjYbWjfmPhtLofp4Xoxh7S9BFyYeE1y4O4xVSwh2q5m0pyWo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=lz0qnyK8; arc=none smtp.client-ip=209.85.221.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="lz0qnyK8" Received: by mail-wr1-f46.google.com with SMTP id ffacd0b85a97d-42fbc305552so3460218f8f.0 for ; Mon, 22 Dec 2025 09:15:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1766423700; x=1767028500; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=OBKBPZnfNYA+sK9uTPKkZCmbZ7hh+vQmMoKO+VyPSj8=; b=lz0qnyK8mIeW2XP8nhKsmgmYkXk69VGRSsLz8/sLyQr2dVafcEvCjCqItimA0N94ki HyXcGn5IrwdhB0aEljJFG8InL7ccePvtRKAvHo3G/rMCQSpatQZjx7Lvll63ga3ja6xk RuBk0B29BXJy7fhNXvcbu9jMVqsXMYDqkPsnAoVhv6MXFw/wtJpLTmpqtgXnh/P4WGPL G8J8q7wLMNX/HGbE5cVNhVQDYXPWOYU7WqzGAWqYvRi0z12vyiG9HzB8vE/dI09CUV2f cml+GxmZ97BqLKulqBR6VuXaQeeqUsM4MPfP/qLCDQ3r0yzIGXC9A9rlnHoC1iZJ0RF7 VdFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766423700; x=1767028500; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=OBKBPZnfNYA+sK9uTPKkZCmbZ7hh+vQmMoKO+VyPSj8=; b=mgDPz8x8luWjAgKjhACF4WioAGe9I7fKdiYoW1YfuFP+TRIaBjvsr98QGgBFQxcYV0 MLPtpyBQER3O9pTiEaSqUjVo1hsFTJPTR2XQLhREKEZRsSoWEwHSyOpBUNPAiN3tTCqV 5EH10Ee5aCFnLYKnYcYNxz8DrdSPu+9ahbW9cL8bNZ7bX6zWoe2uw4A4a3hYkhuXYg8H IlP0Qh7D4FxMsM0IQwuXFembWoPmuf3poRWUSG1mLGhxdA7bWUjtqPmxocoPyjO3ZL5W 3qwoSreDQHyFn192LE4o6Ep3SuUlHmC/xIVwkywjxFEZBtDPoPyXEieAWFvtIDVp8cO4 gbhQ== X-Forwarded-Encrypted: i=1; AJvYcCX6xZnU6kUc1wEYGtoXHRw7urCZQbmJx+bItIOOoe/mJQ4iNQtCaSy7wx8Ae2AVFROJIQ4bLPTcO+WGirc=@vger.kernel.org X-Gm-Message-State: AOJu0YyhS9ixmjFs9sL8HRR6Wen4vGE8YHkSuJ+LA+GB3AM11mVc1hBK sYctGV0A7pDF3WO3TgHvgpo8EigTVcwUkV4AD85ej32gL3qB05phrCXc X-Gm-Gg: AY/fxX7dNFtIF9hsxBBIcAEA4hjQdbRZqAKciXtaZElYpZr9O80OSEbn3ynjh2XvnLN 9y6NGUakxTxVZKDlM+748BxMGzbf7nUX5j8IngVBH+Tc9s2/v5lMz9ZCsnqpn9Jq0yrfCATtljw 72Ut6xMBXt2nZKlwDyFOPyf2DEavcM1q32GNxxHol908sRn+hmw/M9r0SKLVB9f4Rt64TfoY+Oy 5ncYfKM4d6+tj28lAPX3eoZ3R6loxCabF2nun2Q9qVL1mTpJ9OTJmCODXWXdKxUmsRk9zVY62/v kc4COSSQU8KrAaPpxXIt7yeNLcTf0hnXZemR7tTkvs3cJxFplVs6hvL2MaouXNCmk5X4CeatMx9 rrQSnR/qJP991i5nr+vgxzHbkTpFbYXklpW9OwvzHB8bwbpf6nZ4FSmihTGx9czoieYaAfWXxF0 MU1bchytqEGsVN2F3jBNFKk+mBGVTZkj+7pMC0n+pAB8sspm1uCsc= X-Google-Smtp-Source: AGHT+IHqmVu8BHXU9pdCgT4b7EU6k50REs6s6P1D6OnfjG0mmVrBDLDRTIMm8f/zLC2E1PLF11u1sw== X-Received: by 2002:a5d:5f46:0:b0:431:9b2:61c4 with SMTP id ffacd0b85a97d-4324e50d540mr14569390f8f.45.1766423699806; Mon, 22 Dec 2025 09:14:59 -0800 (PST) Received: from pumpkin (host-2-103-239-165.as13285.net. [2.103.239.165]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4324ea227casm23273587f8f.15.2025.12.22.09.14.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Dec 2025 09:14:58 -0800 (PST) Date: Mon, 22 Dec 2025 17:14:57 +0000 From: David Laight To: "Arnd Bergmann" Cc: "Linus Torvalds" , "Nathan Chancellor" , "Nicolas Schier" , linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/1] kbuild: Only enable -Wtautological-constant-out-of-range-compare for W=2 Message-ID: <20251222171457.0b4848a0@pumpkin> In-Reply-To: <8b6d335b-d473-4442-a17f-497ae7996165@app.fastmail.com> References: <20251214131528.3648-1-david.laight.linux@gmail.com> <20251219201231.GB1404453@ax162> <20251219221827.4efa210c@pumpkin> <40f1457c-6e57-4d09-b50e-7133bafa7c3e@app.fastmail.com> <20251220121531.0dae2544@pumpkin> <8b6d335b-d473-4442-a17f-497ae7996165@app.fastmail.com> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; arm-unknown-linux-gnueabihf) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Mon, 22 Dec 2025 11:20:18 +0100 "Arnd Bergmann" wrote: > On Sat, Dec 20, 2025, at 13:15, David Laight wrote: > > On Sat, 20 Dec 2025 11:27:13 +0100 > >> > >> This does seem like a completely sensible warning to me, and it's > >> always been enabled by default. I see three patches in the git history > >> (all from Nathan), which all make sense as well. > >> > >> > Inside FIELD_PREP_CONST(mask, val) there is (with the patch, and if I've > >> > typed it correctly): > >> > BUILD_BUG_ON_ZERO(!(mask) || (mask) & ((mask) + ((mask) & -(mask))))) > >> > to check the mask is non-zero and contiguous bits. > >> > >> I think the problem is (as so often) the linux/bitfield.h headers > >> making things way too complicated. That condition makes no sense to > >> me, and neither would I expect a compiler to make sense of it either. > > > > It is simple really :-) > > -mask is (~mask + 1) so its lowest set bit is the same at that of mask. > > Adding mask changes the adjacent 1s to zeros. > > Anding with mask is then any high bits that are the same in both. > > So is non-zero if mask has noncontiguous bits in it. > > The bit that I find most confusing here is how you have a boolean '||' > operation of two integers, but then interpret the result as an > integer again. I'm not sure what you are getting at. The BUILD_BUG() macros want a 'boolean' argument. The _ON_ZERO() is the return value, nothing to do with the argument. So LHS of the || is 'boolean' and the RHS has the implicit conversion. > > Adding ' == 0' and ' != 0' would just make the line longer. > > I don't think we care about the link length here at all. > Splitting it up into two BUILD_BUG_ON() or BUILD_BUG_ON_ZERO() > lines would help here as well. I'm merging them to reduce bloat..... It's not as though either test fails often enough to need separate error messages. > >> If there is no way to express those conditions more clearly, I would > >> prefer removing the BUILD_BUG_ON stuff from the bitfield.h header, > >> it keeps causing way more false positives than finding actual bugs > >> with the input. > > > > I was just trying to reduce the .i lines line from 18KB for a typical use. > > That seems like a worthwhile goal, but I think the only way to > make an actual impact here is to reduce the fan-out and evaluate > 'mask' less than the current five times in that line (plus additional > evalations. If the 'mask' value is defined using complex macros > like ilog2() or max3() already, the expansion explodes. It usually comes from GENMASK() and that is several hundred characters. Changing type_max(type) to (type)-1 would help that a lot (type is unsigned). Even changing type_max() to do (2 * (x - 1) + 1) instead of ((x - 1) + x) saves quite a long expansion. > Unfortunately the constant version of these macros can't use > compound statements, otherwise we could use an __auto_type temporary > here. Fortunately there aren't that many uses of the _CONST version. The change to bitmask.h that show this 'bug' used _auto_type to reduce bloat for the common case. > > > Probably the only useful check is statically_true(hi < lo) in GENMASK. > > Agreed, that one is clearly worth keeping. > > Arnd