From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45]) (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 1663613FEE for ; Sat, 20 Dec 2025 12:15:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.45 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766232936; cv=none; b=YMtNxRIcR5EVF7111LW07RFpsk4kk0fohRnlVf+0ZoAXRw68RXwhrpMgMc+eJnr7FsCVhEGbJma2INwuSNW448PDaA4zOmznAIEXg9bvrNuZmRLw3AG1qFt1jjRfjAgnDKFWGaT8ptSajfbctXntRsww1MWDGk5vxqkw9Z7g2TU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766232936; c=relaxed/simple; bh=HT6rGisAzJrATVoHaTjefftalkSsNqwoPak/aLxYEP4=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=TnveL36t82OwaKceGt8be7fV0VV1s3p9ZLWgy3VSHp4i58RGBYPd6m/+ytMAPFWu6FntWDT47Ww4JH5+azMjviNe21JXdoZyuFCflv+gOABsNe8ye5sNQkR+F0hWZf+RWQx/hdv2vUlJHCSVkonlUszXv5B73HuOeLHwAhXb3lU= 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=LhKZBA+m; arc=none smtp.client-ip=209.85.221.45 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="LhKZBA+m" Received: by mail-wr1-f45.google.com with SMTP id ffacd0b85a97d-430f9ffd4e8so1697013f8f.0 for ; Sat, 20 Dec 2025 04:15:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1766232933; x=1766837733; 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=0iELTgggMQoPNj9yF64m2G8T+d+6iv2FEFJAnnAfMx8=; b=LhKZBA+mfOiNHh7YwA8FOIk3Zr9nFSSdJZFYAad9KGKDPwQ1BFuzubpoyzxrpgFTfa pqaN/UdpxcFgN5zvCUnlV1qncqu27K/hLiohzZ5RxCtn9u76YZL/f1viAyFTj1m08AoY 0cU3ysT9f0gy1qXrSyqFZzIAiN+pFSptx7qS1s4Q+Z4KAS4wEJjD+EC82lk3loeVRqVZ edwdcGyt98yzQMXCFnMCDRGyGDKaU9gUp9aLeiqDsqv68qcEtgAM71Jx723arEInxPD0 dztNnKjVQD7S0pTRtpMYIW87iDIoKRoH7+ek74fWI00Xq0J6BhAAn40THp7rQPkjq4u7 7dkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766232933; x=1766837733; 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=0iELTgggMQoPNj9yF64m2G8T+d+6iv2FEFJAnnAfMx8=; b=Dwg1fAnrkx3td7iMA0X3AC7LBXv1yAkCyOjfzA2oUBUxWJjgTe5ucuZizwwaQ3WDF1 ILAJXZBEayuwNiszQN7vpQlJ24X9/G+JGmHhxI4luY6SeCiictDV5QgAkzKj0Or3x2lg 4Mf7nZ8w4C/Cdk7uOXDxV3cuhigo1/mkR1D/1CZCFYKt3OaszfxHKvwhaAQ/idZeRFmk W9bMNlBzirZ1QCDwPYMiHI46N8T+hutCXqyTjTdOdUijEd6DaUGFHrSQuwkhc9q9rmcZ jiW9wPUlLlATWJUI1tw79cLE1iZIMb9MD3JFRHUNZagORBBdVoqBwdBiIyJ0ljWEFVCO KH6w== X-Forwarded-Encrypted: i=1; AJvYcCWNA6U1ju5XHILxnHEOf/rfgGtY7b9UayOY0JxReh302qpD/BiIsJhin/BSGtqmI1ce5Zq3GqQuS/5CDy4=@vger.kernel.org X-Gm-Message-State: AOJu0YzRkAd39+tlSQpbmhoBqF3BWq5w5FZkp0hfsKk0TeAIHsTHZCld XdCVltadNL5MHHtlOGOCQGMA9mX45+Rvx0vGnyUccA1vHwkKTPqmjsCD X-Gm-Gg: AY/fxX50EFFA45M4SZ5oNmZxQxS9SVNKdk0iW/RbWaoaA/6cAPi8Grsc0fbmwFxs1o0 SRDxoUzD5LQTktnyZOoJisFpA4zEkxsRPPGMXeKye8+jdmrFKGYL7t8LqSkoLNwTrAdK4Ho5by/ Bpai7Piy4pFsyADTkaLIiBQzKyi5h+8czodeI9IzNu1cfyPEBgrr9duyPIXqfXueXGjqtj6XaMk fcqPcwO0zS3tfhy+YErQA13ATFm4BUZkgsaVY5wlSQnAtYqXdcb/jOz/dERoMWO39HL517rW0ag z4sl9gysrIP1DI33rzZGjclXKwKf7iCV1yglREJe7YXsgKONx1TQiNjBzmnKc6QHjDZ6AiA6yYx WkfFAL78aAZ6VP29Q9kipzwC0yS3lD+/FZQekeontj8imtdbD07Yp7YOt6PUp6SeZySo/bC73Wo AIJF3Z5nKXHij9Z0wc6w/Symd3+x9xFYubb76RO6KKyFpQnAqHvEp0nwdxheu50iw= X-Google-Smtp-Source: AGHT+IFQoE4QDWQr8T1wZVNOYSd+3Uu6vakq96tn+Zj5GkyDF7taAVFShsYizNWCCMZfEV2IPRwWJA== X-Received: by 2002:a05:6000:2011:b0:429:cb8b:b58e with SMTP id ffacd0b85a97d-4324e437982mr6834081f8f.28.1766232933035; Sat, 20 Dec 2025 04:15:33 -0800 (PST) Received: from pumpkin (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4324eaa2bdfsm10477146f8f.32.2025.12.20.04.15.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Dec 2025 04:15:32 -0800 (PST) Date: Sat, 20 Dec 2025 12:15:31 +0000 From: David Laight To: "Arnd Bergmann" , Linus Torvalds Cc: "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: <20251220121531.0dae2544@pumpkin> In-Reply-To: <40f1457c-6e57-4d09-b50e-7133bafa7c3e@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> 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 Sat, 20 Dec 2025 11:27:13 +0100 "Arnd Bergmann" wrote: > On Fri, Dec 19, 2025, at 23:18, David Laight wrote: > > On Fri, 19 Dec 2025 13:12:31 -0700 Nathan Chancellor wrote: > > > > Somewhere I got confused and must have looked at the wrong email (or just > > failed to separate two very long warning names). > > The actual warning was: > > > >>> drivers/gpu/drm/xe/xe_guc.c:639:19: error: converting the result of '<<' to a boolean always evaluates to true [-Werror,-Wtautological-constant-compare] > > 639 | klvs[count++] = > > PREP_GUC_KLV_TAG(OPT_IN_FEATURE_EXT_CAT_ERR_TYPE); > > 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. Adding ' == 0' and ' != 0' would just make the line longer. > > 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. But maybe the whole set of checks is entirely pointless. The simple FIELD_PREP() is just ((val * (mask & -mask)) & mask). FIELD_GET() can be (reg & mask)/(mask & -mask) for constants, but that isn't 'nice' if mask is a variable, (reg & mask) >> ffs(mask) is better. But you only want to use builtin_ffs() for constants so do need to select between __ffs() and __ffs64() for variables - three cases. There is also no point in the u8 and u16 variants (same for GENMASK()). The values get promoted to 'int' and 'unsigned int' would be better. Maybe I'll do a 'dump all the crap' commit. Probably the only useful check is statically_true(hi < lo) in GENMASK. David > > Arnd