From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qk1-x729.google.com (mail-qk1-x729.google.com [IPv6:2607:f8b0:4864:20::729]) by sourceware.org (Postfix) with ESMTPS id 8D99E3858C53 for ; Tue, 26 Apr 2022 20:42:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8D99E3858C53 Received: by mail-qk1-x729.google.com with SMTP id n185so1650383qke.5 for ; Tue, 26 Apr 2022 13:42:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=aqCcCPy2TTed30QLn8GHBHjPh9iFg8qH41wvxMqtQq0=; b=7oif8HpPysVd4PFtUBh30uTxSN4BYTNcuh+XWh6BtROETw4Y7zJYwysFdCWvacP6UF wR0oXvkm/CiQhuJGnwou1Oev8OMHRS0Tve99VXZuS6NJ4cVFDsQ6o3RzUT3ACEd+HZXp r/tEkjwlmPjbdUlsOo9LChH6EjhcZ/h2oJnrHizwSkaV+EhB2os82GBolBmR7ya0JbUz IZgd1CLs2m+zTS8uPI8kycowMfw1UtXKz0cdqGQLg4X50hCs65d8qo3L+fbSRaygp9JV v4OO3Rtda16jyPJmttPs8TJIjjU+6kJseYhQgRyfw77wSYs673S+wMipnClbDrhHW3TU FeJw== X-Gm-Message-State: AOAM532aU8Zv8KZugmuYNA0Nr7PcLQfenwIA94Ohm344CtysFbJBLb4I alfJSXdVsPj0msXUhTSMEsk= X-Google-Smtp-Source: ABdhPJxUnfKJYzMFarhjolTfZCwBsFQOSo8RPgKG9GA+1KlQQLExQbXP2nrwBTmBQD5PuSwffdJCEg== X-Received: by 2002:a05:620a:4625:b0:69f:6a9a:ccd5 with SMTP id br37-20020a05620a462500b0069f6a9accd5mr5330210qkb.626.1651005771686; Tue, 26 Apr 2022 13:42:51 -0700 (PDT) Received: from localhost ([2601:c4:c432:bf1:e227:a1a1:faa3:ec7e]) by smtp.gmail.com with ESMTPSA id y7-20020a05620a0e0700b00699a30d6d10sm6734033qkm.111.2022.04.26.13.42.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Apr 2022 13:42:50 -0700 (PDT) Date: Tue, 26 Apr 2022 13:42:49 -0700 From: Yury Norov To: Vincent Mailhol Cc: Andy Shevchenko , Rasmus Villemoes , Nathan Chancellor , Nick Desaulniers , Tom Rix , linux-kernel@vger.kernel.org, Arnd Bergmann , gcc@gcc.gnu.org, Rikard Falkeborn Subject: Re: [PATCH] linux/find: ignore -Wtype-limits to reduce W=2 warnings by 34% tree-wide Message-ID: References: <20220426161658.437466-1-mailhol.vincent@wanadoo.fr> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220426161658.437466-1-mailhol.vincent@wanadoo.fr> X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 26 Apr 2022 20:42:54 -0000 + 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? 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. Thanks, Yury > Signed-off-by: Vincent Mailhol > --- > include/linux/find.h | 6 ++++++ > 1 file changed, 6 insertions(+) > > diff --git a/include/linux/find.h b/include/linux/find.h > index 5bb6db213bcb..efd4b3f7dd17 100644 > --- a/include/linux/find.h > +++ b/include/linux/find.h > @@ -103,6 +103,10 @@ unsigned long find_next_zero_bit(const unsigned long *addr, unsigned long size, > } > #endif > > +__diag_push(); > +__diag_ignore(GCC, 8, "-Wtype-limits", > + "GENMASK(size - 1, 0) yields 'comparison of unsigned expression in < 0 is always false' which is OK"); > + > #ifndef find_first_bit > /** > * find_first_bit - find the first set bit in a memory region > @@ -193,6 +197,8 @@ unsigned long find_last_bit(const unsigned long *addr, unsigned long size) > } > #endif > > +__diag_pop(); /* ignore -Wtype-limits */ > + > /** > * find_next_clump8 - find next 8-bit clump with set bits in a memory region > * @clump: location to store copy of found clump > -- > 2.35.1