Setters for `addrspace`?

Hello all,

I’ve found the need to fixup address spaces in some code I’m writing. I’m puzzled by the fact that there are no setters for addrspace: For example, in GetElementPtrInst’s API, or in CastInst and its subclasses.

I believe there is some rationale for this I’m missing. Could someone please fill me in?

Cheers,
~Siddharth.

Hi Siddharth,

The addrspace is a property of pointer types, not of instructions. But types are immutable. And if I'm not mistaken you can't change the target type of a CastInst. To set the addrspace of the target type of a CastInst, you have to create a new pointer type with the desired addrspace and create a new CastInst with this type as the target type. You may want to `replaceUsesOfWith` the old with the new instruction and / or delete the old instruction as well.

-Manuel