Skip to content

Commit 37de933

Browse files
committed
Fix spurious CI filures due to OOM
Fixes rust-lang#66342
1 parent bc0e288 commit 37de933

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/librustc_mir/transform/const_prop.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use rustc::ty::subst::InternalSubsts;
2222
use rustc_data_structures::fx::FxHashMap;
2323
use rustc_index::vec::IndexVec;
2424
use rustc::ty::layout::{
25-
LayoutOf, TyLayout, LayoutError, HasTyCtxt, TargetDataLayout, HasDataLayout,
25+
LayoutOf, TyLayout, LayoutError, HasTyCtxt, TargetDataLayout, HasDataLayout, Size,
2626
};
2727

2828
use crate::rustc::ty::subst::Subst;
@@ -35,6 +35,9 @@ use crate::interpret::{
3535
use crate::const_eval::error_to_const_error;
3636
use crate::transform::{MirPass, MirSource};
3737

38+
/// The maximum number of bytes that we'll allocate space for a return value.
39+
const MAX_ALLOC_LIMIT: u64 = 1024;
40+
3841
pub struct ConstProp;
3942

4043
impl<'tcx> MirPass<'tcx> for ConstProp {
@@ -316,8 +319,10 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
316319
ecx
317320
.layout_of(body.return_ty().subst(tcx, substs))
318321
.ok()
319-
// Don't bother allocating memory for ZST types which have no values.
320-
.filter(|ret_layout| !ret_layout.is_zst())
322+
// Don't bother allocating memory for ZST types which have no values
323+
// or for large values.
324+
.filter(|ret_layout| !ret_layout.is_zst() &&
325+
ret_layout.size < Size::from_bytes(MAX_ALLOC_LIMIT))
321326
.map(|ret_layout| ecx.allocate(ret_layout, MemoryKind::Stack));
322327

323328
ecx.push_stack_frame(

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

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// check-pass
2+
3+
fn foo() -> [u8; 4 * 1024 * 1024 * 1024 * 1024] {
4+
unimplemented!()
5+
}
6+
7+
fn main() {
8+
foo();
9+
}

0 commit comments

Comments
 (0)