[cfe-dev] Got compile error 'comparison between non-overlapping address spaces' on 3.6 branch
David Chisnall
David.Chisnall at cl.cam.ac.uk
Thu Feb 12 23:57:33 PST 2015
On 13 Feb 2015, at 06:17, Sameer Sahasrabuddhe <sameer.sahasrabuddhe at amd.com> wrote:
>
> As far as I can see, the C spec defines the literal "0" as the null pointer, so the following macro seems better:
>
> #define NULL 0
While this is technically true (a null pointer constant is an integer constant expression that evaluates to 0 or such an expression cast to a pointer type), a lot of C code will break on LP64 platforms in exciting and difficult-to-debug ways if the NULL macro does not contain the void* cast. The simplest case is a variadic function that expects a NULL terminator. If this now ends with NULL-defined-as-0, the caller will stick 4 bytes of 0 on the stack and the callee may see a NULL terminator or may see something else, depending on what the adjacent 4 bytes on the stack already contain.
For CHERI, we have made clang special-case pointer casts of zero integer pointer expressions for this reason.
David
More information about the cfe-dev
mailing list