Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp63287pxb; Mon, 18 Oct 2021 20:41:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzkqe69ShFirzyMvWTk9GmGD8QHXxrhmhv9d3u/5EiicVGIcePKxPG8rxg9iDdmUv8Mdd2V X-Received: by 2002:a17:907:7803:: with SMTP id la3mr36181632ejc.235.1634614893842; Mon, 18 Oct 2021 20:41:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634614893; cv=none; d=google.com; s=arc-20160816; b=nUPNHXAGZLAvo+HUN6hy3ApVopjWV8nDRN8m6EJ0AafVSBIkh6jMQn4Cmcogh4dN25 LJ/eZ7TD45LwJPYcCM9qLVpY0MOgmjuI8qiF2ISpemvKTWBfEGYPRePHiMeDK/ox2fyo R1mDC8klL9NtTBUPr+y2lSh5K+l3e1qjNcQClK8vpIg/qTFSb8eRxw6awm4+9mtXPvz5 BlvZsEsvvGtyXPd0A7lPHfS77GW2UUaE6VQHtwZYfQr/4TpH7+cluLmZ8PB7JF5/Zlji S+794SI3MInIOcgL5Fat4eL3ATmvvS84NOyExpj9iO0eHgyWoUoUJ1mtrLi6KY27XUBC 4zOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=8/Vo8naa2pVOSCfV4UFA2BJ46wmQrSEVSsBZouXgR8Q=; b=uWKFGLcJHT4I8ds13LDazxspd6m/IE+rfRkBEmYp/DX8Bi7dQ8kca8UX6LmgJQrDXS F8IfHrjrxSnUjNqhOY3lBbtIGmmdBxkDyQXgJoAzdmr49G96JFNrSfJzwWMts/c531SL I8zMQbfibAjKk3w346goQt7Va6TE06XKCx1jwoqhibYnHxCKkDYYn0PRcg+ZZbHx9A12 9A0trjytOQCSfiY+Mnqa9cZ5XdCzz1WNVaPa4MesT9efxz7MSAtIwj6wvhQO5xizIzu5 f8Zw2BE3LXBxcCTSJQgwpxZR/Fyd3Y4ytPa1ppJJL0w9csU8blObE2B2lJN2teIIv4f2 4DRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=TBqUPv05; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b13si29059489ede.122.2021.10.18.20.41.09; Mon, 18 Oct 2021 20:41:33 -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=@linux-foundation.org header.s=google header.b=TBqUPv05; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232498AbhJSDkn (ORCPT + 99 others); Mon, 18 Oct 2021 23:40:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57242 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232488AbhJSDkm (ORCPT ); Mon, 18 Oct 2021 23:40:42 -0400 Received: from mail-lf1-x12b.google.com (mail-lf1-x12b.google.com [IPv6:2a00:1450:4864:20::12b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 88DFCC061745 for ; Mon, 18 Oct 2021 20:38:29 -0700 (PDT) Received: by mail-lf1-x12b.google.com with SMTP id p16so4362107lfa.2 for ; Mon, 18 Oct 2021 20:38:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=8/Vo8naa2pVOSCfV4UFA2BJ46wmQrSEVSsBZouXgR8Q=; b=TBqUPv05LF6J1Ap/h7Pz9XJiHiK0IslnX+9wn7xlIvHPKYKx/hZE2OdYd8/tUHUJiY 5A0XsyYfcM8kS3aHiGgfpEG+nkoekDVqu2WkEHgchyxUgt84AkSR1/G59wXD3IbW6RJ1 4qij4MWM98pZd9rp8BkYS9iuIRoGDWcJuG/YE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=8/Vo8naa2pVOSCfV4UFA2BJ46wmQrSEVSsBZouXgR8Q=; b=VlV49Xq7kFIpeyj27m0r9q2a+41MRMKphotS/h8o8m942XUF+UAxKBaXe8NoX2UzrW amMu87AB6KLtzAgnvqn57vuTpsEWQhU4N3ZowX7JK5Pg0N4TFolgp4OYCx3PrNUMfHfU ut7R3TGnCOVitw+rWodrjNpl3UKt4P/J+S7HrnI+hGzklYuVZZV5CaHWT26oBtZB912t kBxsOMACnLLd8BLv1mBuF31ChL2SlDfuNduK1yKjuVzl6u/w/SVyc4flObTRNMBZw+z5 p9VNlJqf0iyzc0GwEja6qYUHKbPMfv2RmY4fnPnh73OueHKbV21hZelFTdSaH4HF6YLm DkcQ== X-Gm-Message-State: AOAM530AIVHjzrQ7DZCdU/l8qywh//q4evVgVNFH5Q4gplZVdET+I6qR /SK1QkYRJ2S0U+I+xmxbxepXr0xdmD8hCO0p X-Received: by 2002:a05:6512:128b:: with SMTP id u11mr3681831lfs.528.1634614707539; Mon, 18 Oct 2021 20:38:27 -0700 (PDT) Received: from mail-lf1-f42.google.com (mail-lf1-f42.google.com. [209.85.167.42]) by smtp.gmail.com with ESMTPSA id l26sm1551284lfh.247.2021.10.18.20.38.25 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 18 Oct 2021 20:38:26 -0700 (PDT) Received: by mail-lf1-f42.google.com with SMTP id y15so4302787lfk.7 for ; Mon, 18 Oct 2021 20:38:25 -0700 (PDT) X-Received: by 2002:a05:6512:12d4:: with SMTP id p20mr3786322lfg.280.1634614705218; Mon, 18 Oct 2021 20:38:25 -0700 (PDT) MIME-Version: 1.0 References: <20211018182537.2316800-1-nathan@kernel.org> In-Reply-To: From: Linus Torvalds Date: Mon, 18 Oct 2021 17:38:09 -1000 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] platform/x86: thinkpad_acpi: Fix bitwise vs. logical warning To: Nick Desaulniers Cc: Nathan Chancellor , 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 Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. If a warning fix involves making the code uglier, then the warning fix is wrong. This is not the first time we've had compilers suggesting garbage. Gcc used to suggest (perhaps still does) the "extra parenthesis" for "assignment used as a truth value" situation. Which is - once again - disgusting garbage. Writing code like if (a = b) .. is bad and error prone. But the suggestion to "fix" the warning with if ((a = b)) .. is just completely unacceptably stupid, and is just BAD CODE. The proper fix might be to write it like if ((a = b) != 0) ... which at least makes the truth value part explicit - in ways that a silly double parenthesis does not. Or, better yet, write it as a = b; if (a) .. instead, which is legible and fine. The clang suggestion to add a cast to 'int' to avoid the warning is the same kind of "write bad code" suggestion. Just don't do it. Linus