Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp111824pxb; Mon, 18 Oct 2021 22:05:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx5lcCvs92AHyIwKAVJq3L0QS9Jmn8MHCcJPP9ltF7mced+G2IxEBHpnYiJ+1c6jlLc2J+b X-Received: by 2002:a17:907:2658:: with SMTP id ar24mr35159387ejc.405.1634619925180; Mon, 18 Oct 2021 22:05:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634619925; cv=none; d=google.com; s=arc-20160816; b=e4YRf5w1+9LsUeLCKZ6rCHG2FnIYwEja3oJQcapXDIVMErYgTKocceIfahkXoh4Ls8 TX7aDkdrPU24H3GFF4Un6vx++omHTqZ/+pyCyIU0XUUsXfIkI74Wi40Uc3+WELNG7fBR mS6AabfxxfjN/xBh94g/PUCbtnAHDZjjvYVYRNV6g3rf+4zjpjuFkkNAG1Ji9N68B9QW eVk6YtbCgO7aoipCWiRMxfQ4cNpnZsCF3xrfPc4dBrlVXhHo9iyyZeMxZ+oYhU0cnKi5 4o3Njxpk7/4duTENT0a+WmpTdCACo5g/w78D/Wi0wcqC7ntERs0wEqw+ixvFkAKEAPn8 BOFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=TH2mWAiuh8O+EMBblHlqbREkTquB09FcOAX2QkiWNo8=; b=k392NK2vQaVqkU9kVepUPyfsvvB6eYnEmFc3jmc9mn1TlXFKe7SSsBeFyDnCxVhTSW vlcjtTMmZ6DI+0Js5r9omNJqTiXWxeVOhYAxNKOoD5GqiAjmlBShqBV93EQW5NRTrPy3 0dvvGI01Zf2qipXmN/4p1L8hAiaeeQI5iG7q3g8aTromWKlFtadm2N3s6E32zg1Xlm+E jxhNgt1VJ6lIjaBfJ1Jk7ykiyU6vYTso1OFMORtKJCfXvbVYlmT7hYqg0C2qvZDoQj2X j+O3i1o1OA4LDZ7CEC+XOBMXBwYUSdRZpZ/ty1EM4RYJMvwg4yL3qVdv/Mitse31fa4Q 862Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=lhT3gce+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b11si22508517ejg.467.2021.10.18.22.04.51; Mon, 18 Oct 2021 22:05:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=lhT3gce+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229782AbhJSFC3 (ORCPT + 99 others); Tue, 19 Oct 2021 01:02:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:48506 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229649AbhJSFC2 (ORCPT ); Tue, 19 Oct 2021 01:02:28 -0400 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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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