Skip to content

Document the assumptions we make about the C standard library, that go beyond what C requires #426

Closed
rust-lang/rust
#114412
@RalfJung

Description

@RalfJung

See https://reviews.llvm.org/D86993: LLVM, and therefore Rust, assume that memcpy, memmove, memset and possibly other C standard library functions satisfy properties which are not required by the C standard. The least we can do is document this properly. However, I don't know where.

It's not just LLVM though, Rust itself also makes extra assumptions. We explicitly allow zero-sized accesses on pointers such as 42 as *const u8, and this includes zero-sized copy_nonoverlapping, copy and write_bytes. So basically we require zero-sized memcpy, memmove, memset to be a NOP. (Technically it could still be UB for NULL, OOB, or UAF pointers, but we might want to change this on the Rust side and aside from NULL it's not really possibly for implementations to exploit that.) This is justified by us emitting LLVM operations that explicitly say size 0 is a NOP -- but I am not sure what other backends are doing.

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