Disallow branching to the entry block.

Functions that would otherwise start with a loop should start with a
separate ebb which just branches to the header of the loop.
This commit is contained in:
Dan Gohman
2017-10-09 14:59:08 -07:00
parent 893a6716c6
commit 6aeeaebbd3
5 changed files with 133 additions and 116 deletions

View File

@@ -597,11 +597,15 @@ mod test {
#[test]
fn renumbering() {
let mut func = Function::new();
let entry = func.dfg.make_ebb();
let ebb0 = func.dfg.make_ebb();
let ebb100 = func.dfg.make_ebb();
let mut cur = FuncCursor::new(&mut func);
cur.insert_ebb(entry);
cur.ins().jump(ebb0, &[]);
cur.insert_ebb(ebb0);
let cond = cur.ins().iconst(I32, 0);
let inst2 = cur.ins().brz(cond, ebb0, &[]);

View File

@@ -14,6 +14,7 @@
//! - The instruction format must match the opcode.
//! - All result values must be created for multi-valued instructions.
//! - All referenced entities must exist. (Values, EBBs, stack slots, ...)
//! - Instructions must not reference (eg. branch to) the entry block.
//!
//! SSA form
//!
@@ -352,10 +353,14 @@ impl<'a> Verifier<'a> {
fn verify_ebb(&self, inst: Inst, e: Ebb) -> Result {
if !self.func.dfg.ebb_is_valid(e) || !self.func.layout.is_ebb_inserted(e) {
err!(inst, "invalid ebb reference {}", e)
} else {
Ok(())
return err!(inst, "invalid ebb reference {}", e);
}
if let Some(entry_block) = self.func.layout.entry_block() {
if e == entry_block {
return err!(inst, "invalid reference to entry ebb {}", e);
}
}
Ok(())
}
fn verify_sig_ref(&self, inst: Inst, s: SigRef) -> Result {