MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / unreachable_node

Function unreachable_node

cranelift/codegen/src/dominator_tree.rs:596–647  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

594
595 #[test]
596 fn unreachable_node() {
597 let mut func = Function::new();
598 let block0 = func.dfg.make_block();
599 let v0 = func.dfg.append_block_param(block0, I32);
600 let block1 = func.dfg.make_block();
601 let block2 = func.dfg.make_block();
602 let trap_block = func.dfg.make_block();
603
604 let mut cur = FuncCursor::new(&mut func);
605
606 cur.insert_block(block0);
607 cur.ins().brif(v0, block2, &[], trap_block, &[]);
608
609 cur.insert_block(trap_block);
610 cur.ins().trap(TrapCode::unwrap_user(1));
611
612 cur.insert_block(block1);
613 let v1 = cur.ins().iconst(I32, 1);
614 let v2 = cur.ins().iadd(v0, v1);
615 cur.ins().jump(block0, &[v2.into()]);
616
617 cur.insert_block(block2);
618 cur.ins().return_(&[v0]);
619
620 let cfg = ControlFlowGraph::with_function(cur.func);
621 let dt = DominatorTree::with_function(cur.func, &cfg);
622
623 // Fall-through-first, prune-at-source DFT:
624 //
625 // block0 {
626 // brif block2 {
627 // trap
628 // block2 {
629 // return
630 // } block2
631 // } block0
632 assert_eq!(dt.cfg_postorder(), &[block2, trap_block, block0]);
633
634 let v2_def = cur.func.dfg.value_def(v2).unwrap_inst();
635 assert!(!dt.dominates(v2_def, block0, &cur.func.layout));
636 assert!(!dt.dominates(block0, v2_def, &cur.func.layout));
637
638 assert!(dt.block_dominates(block0, block0));
639 assert!(!dt.block_dominates(block0, block1));
640 assert!(dt.block_dominates(block0, block2));
641 assert!(!dt.block_dominates(block1, block0));
642 assert!(dt.block_dominates(block1, block1));
643 assert!(!dt.block_dominates(block1, block2));
644 assert!(!dt.block_dominates(block2, block0));
645 assert!(!dt.block_dominates(block2, block1));
646 assert!(dt.block_dominates(block2, block2));
647 }
648
649 #[test]
650 fn non_zero_entry_block() {

Callers

nothing calls this directly

Calls 9

make_blockMethod · 0.80
jumpMethod · 0.80
value_defMethod · 0.80
newFunction · 0.50
append_block_paramMethod · 0.45
insert_blockMethod · 0.45
insMethod · 0.45
trapMethod · 0.45
unwrap_instMethod · 0.45

Tested by

no test coverage detected