Skip to content

Commit a007e7b

Browse files
committed
Reword explanation for ignoring ZST 1-aligned references
1 parent a2f44ac commit a007e7b

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

compiler/rustc_middle/src/ty/layout.rs

+15-5
Original file line numberDiff line numberDiff line change
@@ -3496,6 +3496,9 @@ fn make_thin_self_ptr<'tcx>(
34963496
/// Determines if this type permits "raw" initialization by just transmuting some
34973497
/// memory into an instance of `T`.
34983498
///
3499+
/// If called with InitKind::Uninit, this function must always panic if a 0x01 filled buffer would
3500+
/// cause LLVM UB.
3501+
///
34993502
/// This code is intentionally conservative, and will not detect
35003503
/// * making uninitialized types who have a full valid range (ints, floats, raw pointers)
35013504
/// * uninit `&T` where T has align 1 size 0 (only inside arrays).
@@ -3547,11 +3550,18 @@ where
35473550
// See: https://github.com/rust-lang/rust/pull/99389
35483551
if inside_array {
35493552
match init_kind {
3550-
// FIXME(#66151) We need to ignore uninit references with an alignment of 1 and
3551-
// size 0
3552-
// (as in, &[u8] and &str)
3553-
// Since if we do not, old versions of `hyper` with no semver compatible fix
3554-
// (0.11, 0.12, 0.13) break.
3553+
// We panic if creating this type with all 0x01 bytes would
3554+
// cause LLVM UB.
3555+
//
3556+
// Therefore, in order for us to not panic,
3557+
// * the alignment of the pointer must be 1
3558+
// (or we would have an unaligned pointer)
3559+
//
3560+
// * the statically known size of the pointee must be 0.
3561+
// (or we would emit dereferenceable)
3562+
//
3563+
// If this bypass didn't exist, old versions of `hyper` with no semver compatible
3564+
// fix (0.11, 0.12, 0.13) would panic, as they make uninit &[u8] and &str.
35553565
InitKind::Uninit => {
35563566
if let ty::Ref(_, inner, _) = this.ty.kind() {
35573567
let penv = ty::ParamEnv::reveal_all().and(*inner);

0 commit comments

Comments
 (0)