Skip to content

Casting between address spaces using bitcasts is UB.Β #264

@FractalFir

Description

@FractalFir

In both NVVM IR & LLVM in general, using bitcasts to change address spaces is UB:

bitcast on pointers is supported, though LLVM IR forbids bitcast from being used to change the address space of a pointer.

The addrspacecast IR instruction should be used to perform pointer casts across address spaces (generic to non-generic or non-generic to generic). Casting a non-generic pointer to a different non-generic pointer is not supported. Casting from a generic to a non-generic pointer is undefined if the generic pointer does not point to an object in the target non-generic address space.

However, we do use bitcasts quite liberally in cg_nvvm, frequently to change the address space of a pointer.

llvm::LLVMBuildPointerCast(bx.llbuilder, alloca, self.cx().type_ptr(), UNNAMED)

We should use address space casts here instead. The main problem will probably be catching all the places where we do this sort of thing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    I-unsound πŸ’₯Issue: A soundness hole on the CPU or the GPU

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions