Skip to content

Detect incorrect use of ZST in the allocator? #3208

@RalfJung

Description

@RalfJung

rust-lang/rust#113113 fixed some bugs in ZST handling of the core collections. I wonder if there is a way that Miri could help find those bugs?

Unfortunately the Rust global allocator says that allocating ZST is UB, so when the collections use the global allocator then ZST allocations never reach Miri -- or put differently, there's not actually a bug with Vec<T, Global>. So I guess to detect this we'd have to explicitly use Vec<T, System>? Then we could make the Miri implementation of malloc actually create a new (zero-sized) allocation on malloc(0), and so failing to pass that to free would be a leak. Passing a dangling pointer to free is already UB (except if it is NULL) so we should also be able to detect that case.

However, currently I don't think that would help. System::alloc ends up here so we never end up even calling malloc(0). I guess we'd need our own allocator for this test that wraps malloc more directly?

Cc @thomcc @Amanieu maybe you have some further ideas here.

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