()
| 93 | |
| 94 | #[test] |
| 95 | fn switch_error() { |
| 96 | use cranelift_codegen::settings; |
| 97 | |
| 98 | let sig = Signature { |
| 99 | params: vec![AbiParam::new(types::I32)], |
| 100 | returns: vec![AbiParam::new(types::I32)], |
| 101 | call_conv: CallConv::SystemV, |
| 102 | }; |
| 103 | |
| 104 | let mut func = Function::with_name_signature(UserFuncName::default(), sig); |
| 105 | let mut func_ctx = FunctionBuilderContext::new(); |
| 106 | { |
| 107 | let mut bcx: FunctionBuilder = FunctionBuilder::new(&mut func, &mut func_ctx); |
| 108 | let start = bcx.create_block(); |
| 109 | let bb0 = bcx.create_block(); |
| 110 | let bb1 = bcx.create_block(); |
| 111 | let bb2 = bcx.create_block(); |
| 112 | let bb3 = bcx.create_block(); |
| 113 | println!("{start} {bb0} {bb1} {bb2} {bb3}"); |
| 114 | |
| 115 | bcx.declare_var(types::I32); |
| 116 | bcx.declare_var(types::I32); |
| 117 | let in_val = bcx.append_block_param(start, types::I32); |
| 118 | bcx.switch_to_block(start); |
| 119 | bcx.def_var(Variable::new(0), in_val); |
| 120 | bcx.ins().jump(bb0, &[]); |
| 121 | |
| 122 | bcx.switch_to_block(bb0); |
| 123 | let discr = bcx.use_var(Variable::new(0)); |
| 124 | let mut switch = cranelift_frontend::Switch::new(); |
| 125 | for &(index, bb) in &[ |
| 126 | (9, bb1), |
| 127 | (13, bb1), |
| 128 | (10, bb1), |
| 129 | (92, bb1), |
| 130 | (39, bb1), |
| 131 | (34, bb1), |
| 132 | ] { |
| 133 | switch.set_entry(index, bb); |
| 134 | } |
| 135 | switch.emit(&mut bcx, discr, bb2); |
| 136 | |
| 137 | bcx.switch_to_block(bb1); |
| 138 | let v = bcx.use_var(Variable::new(0)); |
| 139 | bcx.def_var(Variable::new(1), v); |
| 140 | bcx.ins().jump(bb3, &[]); |
| 141 | |
| 142 | bcx.switch_to_block(bb2); |
| 143 | let v = bcx.use_var(Variable::new(0)); |
| 144 | bcx.def_var(Variable::new(1), v); |
| 145 | bcx.ins().jump(bb3, &[]); |
| 146 | |
| 147 | bcx.switch_to_block(bb3); |
| 148 | let r = bcx.use_var(Variable::new(1)); |
| 149 | bcx.ins().return_(&[r]); |
| 150 | |
| 151 | bcx.seal_all_blocks(); |
| 152 | bcx.finalize(); |
nothing calls this directly
no test coverage detected