From 7826fce44f5e17004f2ce8f6b6ba0a185fbf16d9 Mon Sep 17 00:00:00 2001 From: Tyler McMullen Date: Thu, 18 Jan 2018 15:33:28 -0800 Subject: [PATCH] On finding an static OOB heap addr, split the Ebb and recompute the CFG. --- lib/cretonne/src/legalizer/heap.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/cretonne/src/legalizer/heap.rs b/lib/cretonne/src/legalizer/heap.rs index 09736925b4..6dd5c11095 100644 --- a/lib/cretonne/src/legalizer/heap.rs +++ b/lib/cretonne/src/legalizer/heap.rs @@ -9,7 +9,7 @@ use ir::{self, InstBuilder, MemFlags}; use ir::condcodes::IntCC; /// Expand a `heap_addr` instruction according to the definition of the heap. -pub fn expand_heap_addr(inst: ir::Inst, func: &mut ir::Function, _cfg: &mut ControlFlowGraph) { +pub fn expand_heap_addr(inst: ir::Inst, func: &mut ir::Function, cfg: &mut ControlFlowGraph) { // Unpack the instruction. let (heap, offset, size) = match func.dfg[inst] { ir::InstructionData::HeapAddr { @@ -29,7 +29,7 @@ pub fn expand_heap_addr(inst: ir::Inst, func: &mut ir::Function, _cfg: &mut Cont dynamic_addr(inst, heap, offset, size, bound_gv, func) } ir::HeapStyle::Static { bound } => { - static_addr(inst, heap, offset, size, bound.into(), func) + static_addr(inst, heap, offset, size, bound.into(), func, cfg) } } } @@ -95,6 +95,7 @@ fn static_addr( size: u32, bound: i64, func: &mut ir::Function, + cfg: &mut ControlFlowGraph, ) { let size = i64::from(size); let offset_ty = func.dfg.value_type(offset); @@ -107,6 +108,13 @@ fn static_addr( // This will simply always trap since `offset >= 0`. pos.ins().trap(ir::TrapCode::HeapOutOfBounds); pos.func.dfg.replace(inst).iconst(addr_ty, 0); + + // Split Ebb, as the trap is a terminator instruction. + let curr_ebb = pos.current_ebb().expect("Cursor is not in an ebb"); + let new_ebb = pos.func.dfg.make_ebb(); + pos.insert_ebb(new_ebb); + cfg.recompute_ebb(pos.func, curr_ebb); + cfg.recompute_ebb(pos.func, new_ebb); return; }