[PATCH] Support for address space casting in order to map these on the new 'addrspacecast' IR instruction

John McCall rjmccall at gmail.com
Thu Nov 28 22:39:41 PST 2013


On Nov 27, 2013, at 12:02 AM, Michele Scandale <michele.scandale at gmail.com> wrote:
>  in origin I had the same feeling, as you can see in the first patch I proposed there was a CK_AddressSpaceCast in order to extend the semantic level to support this (initially just for C-Style casts). Being not so confident, I reduced the modification in order to just fix the code generator.

I agree that we should have at least one address-space-changing cast kind.  We should also introduce an AST assertion that other CKs not be used to change address spaces (of the immediate pointee only, of course).

I would call this an AddressSpaceBitCast to make it clear that a pointer to one address space is being converted completely non-semantically to a different address space.

I say non-semantically because the embedded C spec includes the concept of subset address spaces: e.g. an 8-bit address space at a known offset within a larger address space.  If someone ever feels inclined to support that spec correctly, we'll want address-space conversions other than bit-casts.  It sounds like all of these would eventually turn into the same LLVM addrspacecast instruction, although potentially more than one.

The embedded C spec is not very helpful when it comes to bit-cast address space conversions: you can use a cast, but it has undefined behavior if the result doesn’t point to the same object that the operand logically did: i.e. it’s always undefined if the address spaces are non-overlapping.  I think a more reasonable set of rules to use as a basis for language design here are those for casting a pointer to an integer type: i.e. you’re still within defined behavior as long as you get back to the original type in the end and you’ve round-tripped the value successfully.

It would be natural for static_cast to only be able to apply and reverse conversions between overlapping address spaces, but for reinterpret_cast to have the full power of a C cast (w.r.t. the address space qualifier only, of course).

And for the record, this is new feature work and therefore not appropriate for the release branch.  I hope that the LLVM reviewers didn’t approve the addrspacecast instruction being moved over?  That seems massively out of scope.

John.



More information about the cfe-commits mailing list