Skip to content
This repository was archived by the owner on Apr 5, 2024. It is now read-only.
This repository was archived by the owner on Apr 5, 2024. It is now read-only.

Clarify which inputs are permitted for the offset intrinsic (and the MIR binop) #38

Closed
@RalfJung

Description

@RalfJung

The offset intrinsic compiles to LLVM getelementpointer with inbounds attribute, so the offset must stay in-bounds (or one-past-the-end). However, rustc currently also relies on "offset by 0" to always be legal, even if the pointer passed as input is dangling:

  • In the IntoIterator impl for slices. If the slice is empty, the pointer will be (void*) alignment, but the iterator will still add the length (0) to it.
  • The MIR emitted as slice drop glue does the same, but uses the MIR binop instead of the intrinsic.

So the rules for offset currently seem to be:

  • The resulting pointer has to be a valid, in-bounds pointer or one-past-the-end, OR
  • the offset is 0.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions