From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10578 invoked by alias); 5 Feb 2014 15:55:47 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 10541 invoked by uid 48); 5 Feb 2014 15:55:44 -0000 From: "josh at joshtriplett dot org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/59850] Support sparse-style pointer address spaces (type attributes) Date: Wed, 05 Feb 2014 15:55:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: unknown X-Bugzilla-Keywords: X-Bugzilla-Severity: enhancement X-Bugzilla-Who: josh at joshtriplett dot org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2014-02/txt/msg00450.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59850 --- Comment #7 from Josh Triplett --- (In reply to Tom Tromey from comment #6) > Null pointer constants are treated specially, which makes sense, > but only if they have type "void *" and are in address space 0. Otherwise, they're not a null pointer constant, so they're not treated specially. :) A null pointer constant must be in address space 0; that's for compatibility with the standard definition of NULL, to avoid needing unique NULL constants for each possible address space (USER_NULL, IOMEM_NULL). I don't think it makes sense to treat a 0 in address space 1 as a null pointer constant; safer to give a warning for mixing address spaces. The goal isn't to treat 0 magically as an address in all address spaces; it's specifically to treat NULL as the null for all address spaces. > That is, this works: > > #define NULL ((__attribute__ ((address_space (0))) void *) 0) > __attribute__((address_space (1))) int *p = NULL; > > But this gets a warning: > > #define NULL ((__attribute__ ((address_space (1))) void *) 0) > __attribute__((address_space (0))) int *p = NULL; I can't think of a legitimate reason to have a null pointer constant in a non-zero address space; there's already a null pointer constant, NULL, effectively in all address spaces, so why would you want to redefine it? And on the contrary, I can think of a very good reason to *have* this warning: suppose you wanted to define an INVALID_FOO_POINTER in the foo address space, and you decided to use 0 as the invalid value. You should get a warning if you try to use INVALID_FOO_POINTER with a non-foo pointer type; it shouldn't magically pass silently just because the chosen value is 0. > And so does this: > > #define NULL ((int *) 0) > __attribute__((address_space (1))) int *p = NULL; > > > I'm not sure whether that last one ought to be an error or not. That isn't a null pointer constant, since it isn't (void *); it can't be converted to any other pointer type without warning, and I don't think it's unreasonable to say it can't be converted to any other address space without warning either.