Skip to content

Commit 3732b7a

Browse files
committed
[ConstProp] Avoid OOM crashes by not evaluating large Places
Fixes #66397
1 parent d389f64 commit 3732b7a

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
@@ -458,6 +458,11 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
458458
) -> Option<()> {
459459
let span = source_info.span;
460460

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

463468
// 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)