diff --git a/src/librustc_mir/transform/const_prop.rs b/src/librustc_mir/transform/const_prop.rs index a98c6721e9954..a786d3d823c8c 100644 --- a/src/librustc_mir/transform/const_prop.rs +++ b/src/librustc_mir/transform/const_prop.rs @@ -461,6 +461,11 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { ) -> Option<()> { let span = source_info.span; + // #66397: Don't try to eval into large places as that can cause an OOM + if place_layout.size >= Size::from_bytes(MAX_ALLOC_LIMIT) { + return None; + } + let overflow_check = self.tcx.sess.overflow_checks(); // Perform any special handling for specific Rvalue types. diff --git a/src/test/ui/consts/issue-66397.rs b/src/test/ui/consts/issue-66397.rs new file mode 100644 index 0000000000000..0830c060e56af --- /dev/null +++ b/src/test/ui/consts/issue-66397.rs @@ -0,0 +1,5 @@ +// build-pass + +fn main() { + [0; 4 * 1024 * 1024 * 1024 * 1024]; +}