From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 613CCC433FE for ; Sun, 27 Feb 2022 01:16:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229617AbiB0BRK (ORCPT ); Sat, 26 Feb 2022 20:17:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47196 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229501AbiB0BRI (ORCPT ); Sat, 26 Feb 2022 20:17:08 -0500 Received: from gate.crashing.org (gate.crashing.org [63.228.1.57]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 5434989CC1; Sat, 26 Feb 2022 17:16:33 -0800 (PST) Received: from gate.crashing.org (localhost.localdomain [127.0.0.1]) by gate.crashing.org (8.14.1/8.14.1) with ESMTP id 21R19wb7032672; Sat, 26 Feb 2022 19:09:58 -0600 Received: (from segher@localhost) by gate.crashing.org (8.14.1/8.14.1/Submit) id 21R19uhE032669; Sat, 26 Feb 2022 19:09:56 -0600 X-Authentication-Warning: gate.crashing.org: segher set sender to segher@kernel.crashing.org using -f Date: Sat, 26 Feb 2022 19:09:56 -0600 From: Segher Boessenkool To: Arnd Bergmann Cc: Linus Torvalds , Jakob , Linux Kernel Mailing List , linux-arch , Greg Kroah-Hartman , Thomas Gleixner , Andy Shevchenko , Andrew Morton , Kees Cook , Mike Rapoport , "Gustavo A. R. Silva" , Brian Johannesmeyer , Cristiano Giuffrida , "Bos, H.J." Subject: Re: [RFC PATCH 03/13] usb: remove the usage of the list iterator after the loop Message-ID: <20220227010956.GW614@gate.crashing.org> References: <20220217184829.1991035-1-jakobkoschel@gmail.com> <20220217184829.1991035-4-jakobkoschel@gmail.com> <6DFD3D91-B82C-469C-8771-860C09BD8623@gmail.com> <20220226124249.GU614@gate.crashing.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.2.3i Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Feb 26, 2022 at 11:14:15PM +0100, Arnd Bergmann wrote: > On Sat, Feb 26, 2022 at 1:42 PM Segher Boessenkool > wrote: > > On Wed, Feb 23, 2022 at 11:23:39AM -0800, Linus Torvalds wrote: > > > > That said, we seem to only have two cases of it in the kernel, at > > > least by a x86-64 allmodconfig build. So we could examine the types > > > there, or we could just add '-Wno-shift-negative-value". > > > > Yes. > > > > The only reason the warning exists is because it is undefined behaviour > > (not implementation-defined or anything). The reason it is that in the > > standard is that it is hard to implement and even describe for machines > > that are not two's complement. However relevant that is today :-) > > Could gcc follow the clang behavior then and skip the warning and > sanitizer for this case when -fno-strict-overflow or -fwrapv are used? As I said, we have this implementation choice documented as As an extension to the C language, GCC does not use the latitude given in C99 and C11 only to treat certain aspects of signed '<<' as undefined. However, '-fsanitize=shift' (and '-fsanitize=undefined') will diagnose such cases. They are also diagnosed where constant expressions are required. but that is not at all what we implement currently, we warn much more often. Constant expressions are required only in a few places (#if condition, bitfield length, (non-variable) array length, enumeration declarations, _Alignas, _Static_assert, case labels, most initialisers); not places you will see code like this problem normally. So imo we should just never do this by default, not just if the nasty -fwrapv or nastier -fno-strict-overflow is used, just like we suggest in our own documentation. The only valid reason -Wshift-negative-value is in -Wextra is it warns for situations that always are undefined behaviour (even if not in GCC). Could you open a GCC PR for this? The current situation is quite suboptimal, and what we document as our implementation choice is much more useful! Segher