Skip to content

Commit f8d1c35

Browse files
authored
Rollup merge of #65592 - RalfJung:const-prop-comment, r=wesleywiser
clarify const_prop ICE protection comment This is based on discussion at https://github.com/rust-lang/rust/pull/64890/files#r334555787. That said, why are function arguments the only unsized locals that could remain uninitialized? Couldn't we also fail to initialize some local but still go on with const_prop, and then hit a line that takes a reference to that? Cc @wesleywiser @oli-obk ; I don't know enough about const-prop to understand why this can happen only for function arguments. ~~The PR includes #64890; the only new commit is 05e4e6ba0d5.~~
2 parents 194d193 + f907fbe commit f8d1c35

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

src/librustc_mir/transform/const_prop.rs

+14-11
Original file line numberDiff line numberDiff line change
@@ -518,27 +518,30 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
518518
}
519519
}
520520

521-
// Work around: avoid ICE in miri.
522-
// FIXME(wesleywiser) we don't currently handle the case where we try to make a ref
523-
// from a function argument that hasn't been assigned to in this function. The main
524-
// issue is if an arg is a fat-pointer, miri `expects()` to be able to read the value
525-
// of that pointer to get size info. However, since this is `ConstProp`, that argument
526-
// doesn't actually have a backing value and so this causes an ICE.
521+
// Work around: avoid ICE in miri. FIXME(wesleywiser)
522+
// The Miri engine ICEs when taking a reference to an uninitialized unsized
523+
// local. There's nothing it can do here: taking a reference needs an allocation
524+
// which needs to know the size. Normally that's okay as during execution
525+
// (e.g. for CTFE) it can never happen. But here in const_prop
526+
// unknown data is uninitialized, so if e.g. a function argument is unsized
527+
// and has a reference taken, we get an ICE.
527528
Rvalue::Ref(_, _, Place { base: PlaceBase::Local(local), projection: box [] }) => {
528529
trace!("checking Ref({:?})", place);
529530
let alive =
530531
if let LocalValue::Live(_) = self.ecx.frame().locals[*local].value {
531532
true
532-
} else { false };
533+
} else {
534+
false
535+
};
533536

534-
if local.as_usize() <= self.ecx.frame().body.arg_count && !alive {
535-
trace!("skipping Ref({:?})", place);
537+
if !alive {
538+
trace!("skipping Ref({:?}) to uninitialized local", place);
536539
return None;
537540
}
538541
}
539542

540-
// Work around: avoid extra unnecessary locals.
541-
// FIXME(wesleywiser): const eval will turn this into a `const Scalar(<ZST>)` that
543+
// Work around: avoid extra unnecessary locals. FIXME(wesleywiser)
544+
// Const eval will turn this into a `const Scalar(<ZST>)` that
542545
// `SimplifyLocals` doesn't know it can remove.
543546
Rvalue::Aggregate(_, operands) if operands.len() == 0 => {
544547
return None;

0 commit comments

Comments
 (0)