Skip to content

Commit 92154d0

Browse files
committed
[ConstProp] Avoid OOM crashes by not evaluating large Places
Fixes #66397
1 parent 37de933 commit 92154d0

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/librustc_mir/transform/const_prop.rs

+5
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,11 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
461461
) -> Option<()> {
462462
let span = source_info.span;
463463

464+
// #66397: Don't try to eval into large places as that can cause an OOM
465+
if place_layout.size >= Size::from_bytes(MAX_ALLOC_LIMIT) {
466+
return None;
467+
}
468+
464469
let overflow_check = self.tcx.sess.overflow_checks();
465470

466471
// Perform any special handling for specific Rvalue types.

src/test/ui/consts/issue-66397.rs

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// build-pass
2+
3+
fn main() {
4+
[0; 4 * 1024 * 1024 * 1024 * 1024];
5+
}

0 commit comments

Comments
 (0)