From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from albireo.enyo.de (albireo.enyo.de [37.24.231.21]) by sourceware.org (Postfix) with ESMTPS id DE6DB385DC1B for ; Sun, 26 Apr 2020 11:56:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org DE6DB385DC1B Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=deneb.enyo.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=fw@deneb.enyo.de Received: from [172.17.203.2] (helo=deneb.enyo.de) by albireo.enyo.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) id 1jSftu-0003qy-Py; Sun, 26 Apr 2020 11:56:46 +0000 Received: from fw by deneb.enyo.de with local (Exim 4.92) (envelope-from ) id 1jSftu-00077Q-MW; Sun, 26 Apr 2020 13:56:46 +0200 From: Florian Weimer To: Alexander Monakov via Libc-alpha Cc: DJ Delorie , Alexander Monakov , Andreas Schwab Subject: Re: [patch] Use unsigned constants for ICMP6 filters [BZ #22489] References: Date: Sun, 26 Apr 2020 13:56:46 +0200 In-Reply-To: (Alexander Monakov via Libc-alpha's message of "Sun, 26 Apr 2020 14:25:56 +0300 (MSK)") Message-ID: <87pnbu31fl.fsf@mid.deneb.enyo.de> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00, GIT_PATCH_1, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 26 Apr 2020 11:56:50 -0000 * Alexander Monakov via Libc-alpha: > Computing 1<<31 causes undefined behavior (signed overflow), you get > a warning with -Wshift-overflow=2 and a runtime error with UBSan, > i.e. with -fsanitize=undefined. > > I'd say the situation with -Wsign-conversion warning is more subtle > than your initial mail seemed to imply, normally gcc suppresses warnings > for code originating in system headers unless -Wsystem-headers is also > specified. Here the warning appears where user code expands a macro > defined in a system header, maybe this situation is not properly > handled for -Wsign-conversion in GCC. > > In summary, you need 1u to avoid causing undefined behavior if > a shift left by 31 is possible in practice, and it also happens to > suppress GCC's -Wsign-conversion warning (while there's > nothing undefined about the conversion itself). I believe not of the bits in the array have index 31 at present, so the undefined behavior cannot really occur in practice at this point. Perhaps it makes sense to mention both aspects in the commit message, though.