Skip to content

Tracking where we rely on LLVM giving more guarantees than C #292

Open
@RalfJung

Description

@RalfJung

There are some places where we rely on LLVM having less UB than C does. Seems good to have a list of those, and keep a careful eye for what LLVM does in that space since they might not consider Rust when they adjust their rules here.

  • We rely on LLVM not doing TBAA. This is easy since clang turns type-based alias information into explicit annotations that we just do not emit, so I am not at all worried about this one.
  • We rely on inttoptr being always safe. In C, this is UB for out-of-bounds pointers (except if they are one-past-the-end).
  • We rely on == and <= (and the other comparison operators) on pointers to be always safe, and we'd probably be in trouble even if those were just giving non-deterministic results. Essentially we need them to just compare the underlying integer address and ignore provenance.
  • We rely on LLVM's memcpy/memmove/memset to allow size 0 for all pointers. (This is explicitly allowed by the LangRef: "If <len> is 0, it is no-op modulo the behavior of attributes attached to the arguments.")

If you know of anything else, please let me know so I can add it to the list. :)

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