Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755904Ab3DWO3D (ORCPT ); Tue, 23 Apr 2013 10:29:03 -0400 Received: from mail-vb0-f49.google.com ([209.85.212.49]:60621 "EHLO mail-vb0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754564Ab3DWO3B (ORCPT ); Tue, 23 Apr 2013 10:29:01 -0400 MIME-Version: 1.0 In-Reply-To: References: Date: Tue, 23 Apr 2013 07:29:00 -0700 X-Google-Sender-Auth: XAqMc4-juHW_BNnMmeqk5D59Mro Message-ID: Subject: Re: Unsigned widening casts of binary "not" operations.. From: Linus Torvalds To: David Laight Cc: Ingo Molnar , "H. Peter Anvin" , Thomas Gleixner , David Miller , "Theodore Ts'o" , Linux Kernel Mailing List , "the arch/x86 maintainers" , Network Development , "linux-ext4@vger.kernel.org" Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1294 Lines: 28 On Tue, Apr 23, 2013 at 1:59 AM, David Laight wrote: > > If the narrower type is signed it is probably even more confusing! > The high bits will be preserved unless you are masking off bit 31. Yes. However, that case doesn't trigger with the normal case of small values. So "~4" works fine with widening, in a way that "~4u" does not. Which doesn't mean that you aren't right, it only means that it's harder to check for in sparse. The hacky little patch I sent out with already resulted in a lot of noise for things like "~0u" (UINT_MAX) and the "~4u" use in NLMSG_ALIGNTO, I'd dread to do the same for signed values. That said, with the most minimal value analysis (ie only looking at constants), maybe it wouldn't be too bad. I started out just worrying about the PAGE_MASK case, though, where we're talking about (somewhat complicated) generated constants, and then the signed case is largely irrelevant (although a signed "1 << 31" would - as you say - trigger this same thing too). Linus -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/