rjmccall added a comment.

In https://reviews.llvm.org/D26196#593741, @yaxunl wrote:

> >> It seems the casting from a pointer to different address space is not 
> >> affected by this change. When a null pointer is casted to different 
> >> address space, it is casted the same way as an ordinary pointer, e.g. by 
> >> addrspacecast.
> > 
> > You mean, the code-generation for that knows about your special null 
> > pointer representation?  That is confusing.
>
> Do you mean if a null pointer in one address space is casted to another 
> address space, we should use the specific null pointer representation in the 
> new address space, instead of a simple addrspacecast?


That's the general user expectation, yes: a null pointer should be converted to 
a null pointer.  Technically, whether this required is up to the appropriate 
language standard.

The standard rules for address spaces are laid out by Embedded C (ISO/IEC TR 
18037), which has this to say in 5.1.3p4:

> A non-null pointer into an address space A can be cast to a pointer into 
> another address space B, but such a cast is undefined if the source pointer 
> does not point to a location in B. Note that if A is a subset of B, the cast 
> is always valid; however, if B is a subset of A, the cast is valid only if 
> the source pointer refers to a location in B. A null pointer into one address 
> space can be cast to a null pointer into any overlapping address space.

The wording could be better, but I think this is fairly clearly saying that you 
do need to map null to null.

Now, my understanding is that you're not actually implementing Embedded C, 
you're implementing Open CL.  The Open CL specification that I have on hand 
(v1.1) says that __global, __local, __constant, and __private are disjoint and 
that casts between address spaces are illegal.  So this might not actually 
matter to you.

But if you do need to support these conversions for some reason, the correct 
behavior is to ensure that null is mapped to null.


https://reviews.llvm.org/D26196



_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to