Skip to content

Segfault involving mem::uninitialized using optimizations #22581

Description

@milibopp

I stumbled upon some behaviour, which I had not expected using mem::uninitialized. It has to do with this commit. The essence is, that before the change there was a struct field that remained uninitialized at first and was only set later in the same function. When I tried to run a benchmark using this code compiled with opt-level=3, the program segfaulted.

Now I am perfectly aware, that there are a lot of reasons for why it is dangerous to do that and I am also fine using an Option here. Nonetheless, there are two reasons, why I am still reporting this as an issue:

  • There were no runtime failures after I switched to using an Option, so I suspect that the code should not have crashed trying to drop uninitialized memory during unwinding.
  • The error only occurred in the benchmarks, i.e. with opt-level=3. Manually compiling the same benchmark without optimizations was successful.

Given these observations I wonder, whether there might be a problem with the optimization passes here. I tried to reproduce this issue in a minimal example but did not succeed. (Sorry for that :/)

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