()
| 75 | |
| 76 | #[test] |
| 77 | fn switch_error() { |
| 78 | use cranelift_codegen::settings; |
| 79 | |
| 80 | let sig = Signature { |
| 81 | params: vec![AbiParam::new(types::I32)], |
| 82 | returns: vec![AbiParam::new(types::I32)], |
| 83 | call_conv: CallConv::SystemV, |
| 84 | }; |
| 85 | |
| 86 | let mut func = Function::with_name_signature(UserFuncName::default(), sig); |
| 87 | |
| 88 | let mut func_ctx = FunctionBuilderContext::new(); |
| 89 | { |
| 90 | let mut bcx: FunctionBuilder = FunctionBuilder::new(&mut func, &mut func_ctx); |
| 91 | let start = bcx.create_block(); |
| 92 | let bb0 = bcx.create_block(); |
| 93 | let bb1 = bcx.create_block(); |
| 94 | let bb2 = bcx.create_block(); |
| 95 | let bb3 = bcx.create_block(); |
| 96 | println!("{start} {bb0} {bb1} {bb2} {bb3}"); |
| 97 | |
| 98 | bcx.declare_var(types::I32); |
| 99 | bcx.declare_var(types::I32); |
| 100 | let in_val = bcx.append_block_param(start, types::I32); |
| 101 | bcx.switch_to_block(start); |
| 102 | bcx.def_var(Variable::new(0), in_val); |
| 103 | bcx.ins().jump(bb0, &[]); |
| 104 | |
| 105 | bcx.switch_to_block(bb0); |
| 106 | let discr = bcx.use_var(Variable::new(0)); |
| 107 | let mut switch = cranelift_frontend::Switch::new(); |
| 108 | for &(index, bb) in &[ |
| 109 | (9, bb1), |
| 110 | (13, bb1), |
| 111 | (10, bb1), |
| 112 | (92, bb1), |
| 113 | (39, bb1), |
| 114 | (34, bb1), |
| 115 | ] { |
| 116 | switch.set_entry(index, bb); |
| 117 | } |
| 118 | switch.emit(&mut bcx, discr, bb2); |
| 119 | |
| 120 | bcx.switch_to_block(bb1); |
| 121 | let v = bcx.use_var(Variable::new(0)); |
| 122 | bcx.def_var(Variable::new(1), v); |
| 123 | bcx.ins().jump(bb3, &[]); |
| 124 | |
| 125 | bcx.switch_to_block(bb2); |
| 126 | let v = bcx.use_var(Variable::new(0)); |
| 127 | bcx.def_var(Variable::new(1), v); |
| 128 | bcx.ins().jump(bb3, &[]); |
| 129 | |
| 130 | bcx.switch_to_block(bb3); |
| 131 | let r = bcx.use_var(Variable::new(1)); |
| 132 | bcx.ins().return_(&[r]); |
| 133 | |
| 134 | bcx.seal_all_blocks(); |
nothing calls this directly
no test coverage detected