From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B774F2C88 for ; Tue, 19 Oct 2021 05:00:16 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id 741436128B; Tue, 19 Oct 2021 05:00:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1634619616; bh=voRGktYMNQgpL0Ez2VaMsZ61v2/99fKFy6JwkF43BuQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=lhT3gce+PssaynVzLp51Fbg9+vc3qfHg+krAHyCNMtVoY/xTZj1dyRjA9/erB3w+P 2TI1Xd3vK5RVIApkUV2UadAmGQ0hFTqCHv1u1GXQA/8EuKfDExT2/20QyNFvLQrmof RYxi0aqy7fpct2eEjA9dMxnm8DMF2WyJnw1PEcRLkCT6Fd0MRTL1IshYZ2iMfs4Ko8 ZQtScEe6ERxQjArK19pYhuzDpA783hdVPrYT+gkAJNRzfID7CTOIlief+kjE2m6uwg /CAtp5O0mieOdcRSL9DLzbVWFIfqOen+iBvYjj/JXdo4ci5i9twOuzRITlT6gvfyL/ zaKRX1zPHlXQw== Date: Mon, 18 Oct 2021 22:00:11 -0700 From: Nathan Chancellor To: Linus Torvalds Cc: Nick Desaulniers , Henrique de Moraes Holschuh , Hans de Goede , Mark Gross , ibm-acpi-devel@lists.sourceforge.net, platform-driver-x86@vger.kernel.org, Linux Kernel Mailing List , llvm@lists.linux.dev, Tor Vic Subject: Re: [PATCH] platform/x86: thinkpad_acpi: Fix bitwise vs. logical warning Message-ID: References: <20211018182537.2316800-1-nathan@kernel.org> Precedence: bulk X-Mailing-List: llvm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Mon, Oct 18, 2021 at 05:38:09PM -1000, Linus Torvalds wrote: > On Mon, Oct 18, 2021 at 10:14 AM Nick Desaulniers > wrote: > > > > Right, the patch that added the warning explicitly checks for side effects. > > Well, it's a bit questionable. The "side effects" are things like any > pointer dereference, because it could fault, but if you know that > isn't an issue, then clang basically ends up complaining about code > that is perfectly fine. Maybe it was written that way on purpose, like > the kvm code. > > Now, it's probably not worth keeping that "bitops of booleans" logic - > if it is a noticeable optimization, it's generally something that the > compiler should do for us, but basically clang is warning about > perfectly valid code. > > And what I find absolutely disgusting is the suggested "fix" that > clang gives you. > > If the warning said "maybe you meant to use a logical or (||)", then > that would be one thing. But what clang suggests as the "fix" for the > warning is just bad coding practice. For what it's worth, the suggested fix is the '||' underneath the warning text: In file included from arch/x86/kvm/mmu/tdp_iter.c:5: arch/x86/kvm/mmu/spte.h:318:9: error: use of bitwise '|' with boolean operands [-Werror,-Wbitwise-instead-of-logical] return __is_bad_mt_xwr(rsvd_check, spte) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ || arch/x86/kvm/mmu/spte.h:318:9: note: cast one or both operands to int to silence this warning 1 error generated. Perhaps that hint should also be added to the warning text, like: In file included from arch/x86/kvm/mmu/tdp_iter.c:5: arch/x86/kvm/mmu/spte.h:318:9: error: use of bitwise '|' with boolean operands; did you mean logical '||'? [-Werror,-Wbitwise-instead-of-logical] return __is_bad_mt_xwr(rsvd_check, spte) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ || arch/x86/kvm/mmu/spte.h:318:9: note: cast one or both operands to int to silence this warning 1 error generated. It is late for me but I can push that change to the clang developers and see what they think tomorrow if that would help? Cheers, Nathan