Skip to content

Proposal: disallow @bitCast to/from vectors of pointers #18936

Closed

Description

@xdBronch

Zig Version

0.12.0-dev.2711+f995c1b08

Steps to Reproduce and Observed Behavior

test {
    _ = @as(@Vector(1, *u8), @bitCast(@Vector(1, usize){1}));
}

this test passes as well as the inverse operation

Expected Behavior

regular pointers cannot be @bitCasted, instead requiring either @ptrFromInt or @intFromPtr, vectors should behave the same

Activity

  1. added
    bug
    on Feb 14, 2024
  2. Vexu commented on Feb 18, 2024

    @Vexu
    Member

    @Vector(1, *u8) is not generally considered a "pointer type" like ?*u8. If changed it should apply to more places than just @bitCast.

  3. added
    proposal
    and removed
    bug
    on Feb 18, 2024
  4. added this to the 0.13.0 milestone on Feb 18, 2024
  5. InKryption commented on Feb 18, 2024

    @InKryption
    Contributor

    If changed it should apply to more places than just @bitcast.

    Would it make sense to allow dereferencing a @Vector(n, *T) to get a @Vector(n, T)? Is there any hardware support for something of the sort? If so, that might be worth considering as well.

  6. modified the milestones: 0.14.0, 0.15.0 on Feb 9, 2025
  7. changed the title [-]`@bitCast` allowed to cast to/from vectors of pointers[/-] [+]Proposal: disallow `@bitCast` to/from vectors of pointers[/+] on May 1, 2026
  8. added
    accepted
    on May 1, 2026
  9. mlugg commented on May 1, 2026

    @mlugg
    Member

    Accepted because:

    • You cannot @bitCast to/from scalar pointer values
    • It may be beneficial to avoid treating pointers as simple integer-like values to limit the potential impact of CHERI architectures in the future
  10. modified the milestones: urgent, 0.17.0 on Jun 24, 2026
  11. mlugg commented on Jun 24, 2026

    @mlugg
    Member
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    acceptedproposal

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions