Skip to content

Commit

Permalink
Fix spurious CI filures due to OOM
Browse files Browse the repository at this point in the history
Fixes #66342
  • Loading branch information
wesleywiser committed Nov 15, 2019
1 parent 1bd30ce commit d389f64
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/librustc_mir/transform/const_prop.rs
Expand Up @@ -22,7 +22,7 @@ use rustc::ty::subst::InternalSubsts;
use rustc_data_structures::fx::FxHashMap;
use rustc_index::vec::IndexVec;
use rustc::ty::layout::{
LayoutOf, TyLayout, LayoutError, HasTyCtxt, TargetDataLayout, HasDataLayout,
LayoutOf, TyLayout, LayoutError, HasTyCtxt, TargetDataLayout, HasDataLayout, Size,
};

use crate::rustc::ty::subst::Subst;
Expand All @@ -35,6 +35,9 @@ use crate::interpret::{
use crate::const_eval::error_to_const_error;
use crate::transform::{MirPass, MirSource};

/// The maximum number of bytes that we'll allocate space for a return value.
const MAX_ALLOC_LIMIT: u64 = 1024;

pub struct ConstProp;

impl<'tcx> MirPass<'tcx> for ConstProp {
Expand Down Expand Up @@ -313,8 +316,10 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
ecx
.layout_of(body.return_ty().subst(tcx, substs))
.ok()
// Don't bother allocating memory for ZST types which have no values.
.filter(|ret_layout| !ret_layout.is_zst())
// Don't bother allocating memory for ZST types which have no values
// or for large values.
.filter(|ret_layout| !ret_layout.is_zst() &&
ret_layout.size < Size::from_bytes(MAX_ALLOC_LIMIT))
.map(|ret_layout| ecx.allocate(ret_layout, MemoryKind::Stack));

ecx.push_stack_frame(
Expand Down
9 changes: 9 additions & 0 deletions src/test/ui/consts/issue-66342.rs
@@ -0,0 +1,9 @@
// check-pass

fn foo() -> [u8; 4 * 1024 * 1024 * 1024 * 1024] {
unimplemented!()
}

fn main() {
foo();
}

0 comments on commit d389f64

Please sign in to comment.