@@ -3496,6 +3496,9 @@ fn make_thin_self_ptr<'tcx>(
3496
3496
/// Determines if this type permits "raw" initialization by just transmuting some
3497
3497
/// memory into an instance of `T`.
3498
3498
///
3499
+ /// If called with InitKind::Uninit, this function must always panic if a 0x01 filled buffer would
3500
+ /// cause LLVM UB.
3501
+ ///
3499
3502
/// This code is intentionally conservative, and will not detect
3500
3503
/// * making uninitialized types who have a full valid range (ints, floats, raw pointers)
3501
3504
/// * uninit `&T` where T has align 1 size 0 (only inside arrays).
@@ -3547,11 +3550,18 @@ where
3547
3550
// See: https://github.com/rust-lang/rust/pull/99389
3548
3551
if inside_array {
3549
3552
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.
3555
3565
InitKind :: Uninit => {
3556
3566
if let ty:: Ref ( _, inner, _) = this. ty . kind ( ) {
3557
3567
let penv = ty:: ParamEnv :: reveal_all ( ) . and ( * inner) ;
0 commit comments