Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Panic on invalid usages of MaybeUninit::uninit().assume_init() #100423

Closed

Commits on Feb 22, 2023

  1. Add new CheckMaybeUninit MIR transform

    This MIR transform inserts the same validity checks from
    `mem::{uninitialized,zeroed}` to `MaybeUninit::{uninit,zeroed}().assume_init()`.
    
    We have been panicking in `mem::uninit` on invalid values for quite some
    time now, and it has helped to get people off the unsound API and
    towards using `MaybeUninit<T>`.
    
    While correct usage of `MaybeUninit<T>` is clearly documented, some
    people still use it incorrectly and simply replaced their wrong
    `mem::uninit` usage with `MaybeUninit::uninit().assume_init()`. This
    is not any more correct than the old version, and we should still emit
    panics in these cases. As this can't be done in the library only, we
    need this MIR pass to insert the calls.
    
    For now, it only detects direct usages of
    `MaybeUninit::uninit().assume_init()` but it could be extended in the
    future to do more advanced dataflow analysis.
    Noratrieb committed Feb 22, 2023
    Configuration menu
    Copy the full SHA
    641251b View commit details
    Browse the repository at this point in the history