Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp4836786iob; Mon, 9 May 2022 02:49:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxaILcVDMXRhMwiXP/AKYBaxR0g3ZDObOG4r0K5XdvqU7q2De+L2fi8yMPsOpIE07oFu4PD X-Received: by 2002:a17:90a:348d:b0:1dd:1779:412f with SMTP id p13-20020a17090a348d00b001dd1779412fmr4997297pjb.18.1652089762576; Mon, 09 May 2022 02:49:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652089762; cv=none; d=google.com; s=arc-20160816; b=PfHVCUfZDvtFUhiiNdI2OelEB3rGfwuWzyADq0X5dhF1o2rJLANxcIl0N5Q3w+CT5X VNQvvhdO3n+FYiE2aiaHEeakm/Zhs5UTUFFrvXoD6T+kLM887gsmVcioMFNWRF9+WJiO SAbYROjVsz1uW3sDnvq7JPlg6rmPaf3KJOgbnhQRWUWMw/5Egy07NX8E4CqeHw24593n c6BNP063L2UfksQnB1ErvRGwXktVOlp5uJdhfImX2KlXiM97oJDNxnc36lcGJMxF436L Mza9LMzLZWXqGKdNXHXuoitvgE38osrOppOci2HFbLaxCzy3WUe/3j8xUJcFooK/tWSS ubiQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version; bh=+Do3XPEiTgDQ1Ml++3sGBVhRWvwo70feJbGO+bfDANQ=; b=0bDzti32OOgVO+9e8ru1RoRpzWDJL7dN2gjUrSlMLiK8XsOn07MpKO7spBHfjnKCck mzGmvFxuRDis1yG1eNZdCaP/sovPYhcP9H+1mo6EZMVL8QiAdqA+KMNuzGWVqC1txGsa aE6PRi12G+O3NEekknDEIhpGVMM9giWGyOfBFFX+dbvbVuRf0iCdeJNuzVlr08vCL+BX bYjdiyxxa4NN9M/d22b5sctffKPH6pttYM5qVv5X+rZUd4spoXqrzcwrsS9YqAHiqWOk VIDN83OlYJ8fpSns51vAak6Wv7rOjVWKyFrQn30WlqB69cm7qcY1vVWVklLfLx1wVm8z fVag== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id j13-20020aa78dcd000000b004fa9a8cc0ccsi12655430pfr.100.2022.05.09.02.49.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 May 2022 02:49:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 9C02F22782F; Mon, 9 May 2022 02:34:25 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231912AbiEHJQ4 convert rfc822-to-8bit (ORCPT + 99 others); Sun, 8 May 2022 05:16:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50366 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231431AbiEHJQz (ORCPT ); Sun, 8 May 2022 05:16:55 -0400 Received: from mail-yb1-f176.google.com (mail-yb1-f176.google.com [209.85.219.176]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B137213 for ; Sun, 8 May 2022 02:13:05 -0700 (PDT) Received: by mail-yb1-f176.google.com with SMTP id y2so19962401ybi.7 for ; Sun, 08 May 2022 02:13:05 -0700 (PDT) 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:content-transfer-encoding; bh=SDA5FDwJEY6Sjd/rkwLVsRftMm4AEBLlTFhWKOrKnGI=; b=K2jQ1dIxTHKKZibVnhI655NTti5v3Yp1r+wOKCXVdl1ps/RHSCSt0IRb3+RYTMeOf8 rGZq2jbf12oM2VctmBccpSlFESONVHz6FhSxbTDb3vpYQJC2gm+D0Y36x08HpdMlxYLK rF+AYZGaeFpWsPOTEd3FyNIfDKmPApf15T8Wsd2WXi7CuwNdbW86Pok+g3WLCHdzHm0k emScVLc6U6sc/97ZgMZ6aXweyJ+g9a+gEfkOwWiGXqwroeA6cpyZN1lkiAJ0YJuluKvD 9FdY/MKImKR5k8ko7qSj5cIjB4TnDmpmxbn3O9/tUPTmvaW9F7ybzFt3Pf4vuwl3DIxO Yy5Q== X-Gm-Message-State: AOAM530qZoPAoZJyD68Y3wQSTsnijD9u611M8Ef1bQ0/xoGSv7GPCNqj qYOup+cJDdmUmqqUK3GwRL28v8Pk4ywEVBQ92DI= X-Received: by 2002:a25:e705:0:b0:645:781a:f870 with SMTP id e5-20020a25e705000000b00645781af870mr8262403ybh.630.1652001183959; Sun, 08 May 2022 02:13:03 -0700 (PDT) MIME-Version: 1.0 References: <20220426161658.437466-1-mailhol.vincent@wanadoo.fr> In-Reply-To: From: Vincent MAILHOL Date: Sun, 8 May 2022 18:12:52 +0900 Message-ID: Subject: Re: [PATCH] linux/find: ignore -Wtype-limits to reduce W=2 warnings by 34% tree-wide To: Yury Norov Cc: Andy Shevchenko , Rasmus Villemoes , Nathan Chancellor , Nick Desaulniers , Tom Rix , linux-kernel@vger.kernel.org, Arnd Bergmann , gcc@gcc.gnu.org, Rikard Falkeborn , Alexander Lobakin Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed. 27 Apr 2022 at 11:58, Vincent MAILHOL wrote: > + Alexander Lobakin > On Wed. 27 Apr 2022 at 05:42, Yury Norov wrote: > > + gcc@gcc.gnu.org > > + Rikard Falkeborn > > > > On Wed, Apr 27, 2022 at 01:16:58AM +0900, Vincent Mailhol wrote: > > > find_first_bit(), find_first_and_bit(), find_first_and_bit() and > > > find_first_and_bit() all invokes GENMASK(size - 1, 0). > > > > > > This triggers below warning when compiled with W=2. > > > > > > | ./include/linux/find.h: In function 'find_first_bit': > > > | ./include/linux/bits.h:25:36: warning: comparison of unsigned > > > | expression in '< 0' is always false [-Wtype-limits] > > > | 25 | __is_constexpr((l) > (h)), (l) > (h), 0))) > > > | | ^ > > > | ./include/linux/build_bug.h:16:62: note: in definition of macro > > > | 'BUILD_BUG_ON_ZERO' > > > | 16 | #define BUILD_BUG_ON_ZERO(e) ((int)(sizeof(struct { int:(-!!(e)); }))) > > > | | ^ > > > | ./include/linux/bits.h:25:17: note: in expansion of macro '__is_constexpr' > > > | 25 | __is_constexpr((l) > (h)), (l) > (h), 0))) > > > | | ^~~~~~~~~~~~~~ > > > | ./include/linux/bits.h:38:10: note: in expansion of macro 'GENMASK_INPUT_CHECK' > > > | 38 | (GENMASK_INPUT_CHECK(h, l) + __GENMASK(h, l)) > > > | | ^~~~~~~~~~~~~~~~~~~ > > > | ./include/linux/find.h:119:45: note: in expansion of macro 'GENMASK' > > > | 119 | unsigned long val = *addr & GENMASK(size - 1, 0); > > > | | ^~~~~~~ > > > > > > linux/find.h being a widely used header file, above warning show up in > > > thousand of files which include this header (either directly on > > > indirectly). > > > > > > Because it is a false positive, we just silence -Wtype-limits flag > > > locally to remove the spam. clang does not warn about it, so we just > > > apply the diag_ignore() directive to gcc. > > > > > > By doing so, the warnings for a W=2 build are reduced by > > > 34%. Benchmark was done with gcc 11.2.1 on Linux v5.17 x86_64 > > > allyesconfig (except CONFIG_WERROR). Beforethe patch: 515496 warnings > > > and after: 340097. > > > > > > For reference, past proposal to modify GENMASK_INPUT_CHECK() was > > > rejected in: > > > https://lore.kernel.org/all/20220304124416.1181029-1-mailhol.vincent@wanadoo.fr/ > > > > So, here is nothing wrong with the kernel code and we have an alternative > > compiler (clang) that doesn't throw Wtype-limits. It sounds to me like an > > internal GCC problem, and I don't understand how hiding broken Wtype-limits > > on kernel side would help people to improve GCC. > > > > On the thread you mentioned above: > > > > > > > > Have you fixed W=1 warnings? > > > > > > Without fixing W=1 (which makes much more sense, when used with > > > > > > WERROR=y && COMPILE_TEST=y) this has no value. > > > > > > > > > > How is this connected? > > > > > > > > By priorities. > > > > I don't see much value in fixing W=2 per se if the code doesn't compile for W=1. > > > > > > *My code* compiles for W=1. For me, fixing this W=2 in the next in line > > > if speaking of priorities. > > > > > > I do not understand why I should be forbidden to fix a W=2 in the > > > file which I am maintaining on the grounds that some code to which > > > I do not care still has some W=1. > > > > If you are concerned about a particular driver - why don't you silence > > the warning in there? Or alternatively build it with clang? > > Sorry if my previous comments looked selfish. I used the first > person to illustrate my point but because this W=2 appears in > thousands of files my real intent is to fix it for everybody, not > only for myself. > > > With all that, I think that the right way to go is to fix the root > > cause of this churn - broken Wtype-limits in GCC, and after that move > > Wtype-limits to W=1. Anything else looks hacky to me. > > Why is this use of __diag_ignore() hacky compared when compared > to the other use of __diag_ignore() or the use of -Wno-something > in local Makefiles? > > I did my due diligence and researched GCC’s buzilla before > sending this patch. There is an opened ticket here: > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86647 I would like to withdraw the above statement. After looking deeper, this is not related to the GCC bug in the above link. I was misled by the __is_constexpr() in GENMASK_INPUT_CHECK(): | #define GENMASK_INPUT_CHECK(h, l) \ | (BUILD_BUG_ON_ZERO(__builtin_choose_expr( \ | __is_constexpr((l) > (h)), (l) > (h), 0))) and because of that, I was assuming that the parameters were constant. But actually, in the expression GENMASK(size - 1, 0), the first member is not necessarily constant. The thing is that the warning check occurs before the evaluation of __builtin_choose_expr() and so, it sees the comparaison (l) > (h) and triggers the warning even if the expression is not constant and will be eventually discarded later. On the contrary, for example, GENMASK(9U, 0) works fine (no warning). GCC man pages says: | -Wtype-limits: | Warn if a comparison is always true or always false due | to the limited range of the data type, but do not warn | for constant expressions. For example, warn if an | unsigned variable is compared against zero with "<" | or ">=". So actually, GCC behaves exactly as expected here: emit a warning when comparing a non-constant unsigned variable against zero. In the particular case of GENMASK(), it is harmless, yes, but regardless, -Wtype-limits is not broken here. We might argue against the definition of -Wtype-limits, but I personally think it is good as is so I will not push GCC guys to fix what I do not consider anymore to be a bug on their side. On GCC side, the only thing which could be changed would be to evaluate __builtin_choose_expr() before checking for warnings. But I doubt this is something feasible without creating many side effects on performance. If we refuse to modify GENMASK() or __diag_ignore() it, then all I see left is to move -Wtype-limits to W=3. > In a perfect word, yes, all false positives should be fixed in > the compiler, but the reality is that this bug was reported in > July 2018, nearly four years ago. GCC developers have their own > priorities and fixing this bug does not appear to be part of > those. And I do not have the knowledge of GCC's internals to fix > this myself. So what do we do next, blame GCC and do nothing or > silence it on our side in order to have a mininfull W=2 output? > > > Yours sincerely, > Vincent Mailhol