[PATCH] Support for address space casting in order to map these on the new 'addrspacecast' IR instruction
michele.scandale at gmail.com
Wed Nov 27 00:02:27 PST 2013
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.
In your example, the second case is a bit weird: from LLVM IR a 'i32 addrspace(1)*' and 'i32 addrspace(2)*' may differ in size (the first can be a 16bit pointer, while the second can be a 64bit): so a pure bit-casting in general is not possible. Indeed the specific changes produced by 'addrspacecast' are target specific: on a given target an addrspacecast can be just a bitcast (the target specify that the operation is a No-Op Cast), or may change all the bits truncating or extending the bit sequence.
If I remember correctly, reinterpret_cast is a bitcast iff both source and destination type have the same size in bit (byte?), while in other cases should be enough to truncate or zero extend the value, so the we should emit a ptrtoint+inttoptr.
To solve the semantic incoherence, I think that an extension (w.r.t. C++ casts) of the first patch should be fine.
More information about the cfe-commits