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
Fixes #66397
  • Loading branch information
wesleywiser committed Nov 15, 2019
1 parent d389f64 commit 3732b7a
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 @@ -458,6 +458,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 3732b7a

Please sign in to comment.