3 ms·
Do some Rust types have invalid object representation or trap representation? On SysV x86_64 bool only has two valid representations in memory, the rest are tra
by leni536 2y ago
Do some Rust types have invalid object representation or trap representation? On SysV x86_64 bool only has two valid representations in memory, the rest are trap representations.
So for an array of bools (if Rust matches SysV) freeze wouldn't be sound, even without the madvise problem.
- gpm 2y agoYes. That's what "// SAFETY: u8 has no invalid bit patterns." is discussing. That while types in general can u8 specifically does not (none of the u*/i* integer types do) so freezing a buffer of u8s is sound.
- kmeisthax 2y agoYes; and furthermore LLVM also has undef, which is sort of a trap representation, but it only exists in the optimizer. (There's also poison for overflow, which is a strictly less defined value than undef.) I suspect even reading an array of uninitialized u8s would cause havoc just from LLVM miscompiles alone.