Skip to content

Commit

Permalink
[ConstProp] Avoid OOM crashes by not evaluating large Places
Browse files Browse the repository at this point in the history
  • Loading branch information
wesleywiser committed Nov 14, 2019
1 parent 37de933 commit 92154d0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/librustc_mir/transform/const_prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions src/test/ui/consts/issue-66397.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// build-pass

fn main() {
[0; 4 * 1024 * 1024 * 1024 * 1024];
}

0 comments on commit 92154d0

Please sign in to comment.