microsoft/qdk
Publicmirrored fromhttps://github.com/microsoft/qdkAvailable
source/compiler/qsc_codegen/src/qir/instruction_tests/invalid.rs
199lines · modecode
| 1 | // Copyright (c) Microsoft Corporation. |
| 2 | // Licensed under the MIT License. |
| 3 | |
| 4 | use crate::qir::ToQir; |
| 5 | use qsc_rir::rir; |
| 6 | |
| 7 | #[test] |
| 8 | #[should_panic(expected = "mismatched input types (i64, double) for add")] |
| 9 | fn add_mismatched_literal_input_tys_should_panic() { |
| 10 | let inst = rir::Instruction::Add( |
| 11 | rir::Operand::Literal(rir::Literal::Integer(2)), |
| 12 | rir::Operand::Literal(rir::Literal::Double(1.0)), |
| 13 | rir::Variable { |
| 14 | variable_id: rir::VariableId(0), |
| 15 | ty: rir::Ty::Integer, |
| 16 | }, |
| 17 | ); |
| 18 | let _ = &inst.to_qir(&rir::Program::default()); |
| 19 | } |
| 20 | |
| 21 | #[test] |
| 22 | #[should_panic(expected = "mismatched input/output types (i64, double) for add")] |
| 23 | fn add_mismatched_literal_input_output_tys_should_panic() { |
| 24 | let inst = rir::Instruction::Add( |
| 25 | rir::Operand::Literal(rir::Literal::Integer(2)), |
| 26 | rir::Operand::Literal(rir::Literal::Integer(5)), |
| 27 | rir::Variable { |
| 28 | variable_id: rir::VariableId(0), |
| 29 | ty: rir::Ty::Double, |
| 30 | }, |
| 31 | ); |
| 32 | let _ = &inst.to_qir(&rir::Program::default()); |
| 33 | } |
| 34 | |
| 35 | #[test] |
| 36 | #[should_panic(expected = "mismatched input types (i64, double) for add")] |
| 37 | fn add_mismatched_variable_input_tys_should_panic() { |
| 38 | let inst = rir::Instruction::Add( |
| 39 | rir::Operand::Variable(rir::Variable { |
| 40 | variable_id: rir::VariableId(1), |
| 41 | ty: rir::Ty::Integer, |
| 42 | }), |
| 43 | rir::Operand::Variable(rir::Variable { |
| 44 | variable_id: rir::VariableId(2), |
| 45 | ty: rir::Ty::Double, |
| 46 | }), |
| 47 | rir::Variable { |
| 48 | variable_id: rir::VariableId(0), |
| 49 | ty: rir::Ty::Integer, |
| 50 | }, |
| 51 | ); |
| 52 | let _ = &inst.to_qir(&rir::Program::default()); |
| 53 | } |
| 54 | |
| 55 | #[test] |
| 56 | #[should_panic(expected = "mismatched input/output types (i64, double) for add")] |
| 57 | fn add_mismatched_variable_input_output_tys_should_panic() { |
| 58 | let inst = rir::Instruction::Add( |
| 59 | rir::Operand::Variable(rir::Variable { |
| 60 | variable_id: rir::VariableId(1), |
| 61 | ty: rir::Ty::Integer, |
| 62 | }), |
| 63 | rir::Operand::Variable(rir::Variable { |
| 64 | variable_id: rir::VariableId(2), |
| 65 | ty: rir::Ty::Integer, |
| 66 | }), |
| 67 | rir::Variable { |
| 68 | variable_id: rir::VariableId(0), |
| 69 | ty: rir::Ty::Double, |
| 70 | }, |
| 71 | ); |
| 72 | let _ = &inst.to_qir(&rir::Program::default()); |
| 73 | } |
| 74 | |
| 75 | #[test] |
| 76 | #[should_panic(expected = "mismatched input types (i64, double) for and")] |
| 77 | fn bitwise_and_mismatched_literal_input_tys_should_panic() { |
| 78 | let inst = rir::Instruction::BitwiseAnd( |
| 79 | rir::Operand::Literal(rir::Literal::Integer(2)), |
| 80 | rir::Operand::Literal(rir::Literal::Double(1.0)), |
| 81 | rir::Variable { |
| 82 | variable_id: rir::VariableId(0), |
| 83 | ty: rir::Ty::Integer, |
| 84 | }, |
| 85 | ); |
| 86 | let _ = &inst.to_qir(&rir::Program::default()); |
| 87 | } |
| 88 | |
| 89 | #[test] |
| 90 | #[should_panic(expected = "mismatched input/output types (i64, double) for and")] |
| 91 | fn bitwise_and_mismatched_literal_input_output_tys_should_panic() { |
| 92 | let inst = rir::Instruction::BitwiseAnd( |
| 93 | rir::Operand::Literal(rir::Literal::Integer(2)), |
| 94 | rir::Operand::Literal(rir::Literal::Integer(5)), |
| 95 | rir::Variable { |
| 96 | variable_id: rir::VariableId(0), |
| 97 | ty: rir::Ty::Double, |
| 98 | }, |
| 99 | ); |
| 100 | let _ = &inst.to_qir(&rir::Program::default()); |
| 101 | } |
| 102 | |
| 103 | #[test] |
| 104 | #[should_panic(expected = "mismatched input types (i64, double) for and")] |
| 105 | fn bitwise_and_mismatched_variable_input_tys_should_panic() { |
| 106 | let inst = rir::Instruction::BitwiseAnd( |
| 107 | rir::Operand::Variable(rir::Variable { |
| 108 | variable_id: rir::VariableId(1), |
| 109 | ty: rir::Ty::Integer, |
| 110 | }), |
| 111 | rir::Operand::Variable(rir::Variable { |
| 112 | variable_id: rir::VariableId(2), |
| 113 | ty: rir::Ty::Double, |
| 114 | }), |
| 115 | rir::Variable { |
| 116 | variable_id: rir::VariableId(0), |
| 117 | ty: rir::Ty::Integer, |
| 118 | }, |
| 119 | ); |
| 120 | let _ = &inst.to_qir(&rir::Program::default()); |
| 121 | } |
| 122 | |
| 123 | #[test] |
| 124 | #[should_panic(expected = "mismatched input/output types (i64, double) for and")] |
| 125 | fn bitwise_and_mismatched_variable_input_output_tys_should_panic() { |
| 126 | let inst = rir::Instruction::BitwiseAnd( |
| 127 | rir::Operand::Variable(rir::Variable { |
| 128 | variable_id: rir::VariableId(1), |
| 129 | ty: rir::Ty::Integer, |
| 130 | }), |
| 131 | rir::Operand::Variable(rir::Variable { |
| 132 | variable_id: rir::VariableId(2), |
| 133 | ty: rir::Ty::Integer, |
| 134 | }), |
| 135 | rir::Variable { |
| 136 | variable_id: rir::VariableId(0), |
| 137 | ty: rir::Ty::Double, |
| 138 | }, |
| 139 | ); |
| 140 | let _ = &inst.to_qir(&rir::Program::default()); |
| 141 | } |
| 142 | |
| 143 | #[test] |
| 144 | #[should_panic(expected = "unsupported type i1 for add")] |
| 145 | fn add_bool_should_panic() { |
| 146 | let inst = rir::Instruction::Add( |
| 147 | rir::Operand::Literal(rir::Literal::Bool(true)), |
| 148 | rir::Operand::Literal(rir::Literal::Bool(false)), |
| 149 | rir::Variable { |
| 150 | variable_id: rir::VariableId(0), |
| 151 | ty: rir::Ty::Boolean, |
| 152 | }, |
| 153 | ); |
| 154 | let _ = &inst.to_qir(&rir::Program::default()); |
| 155 | } |
| 156 | |
| 157 | #[test] |
| 158 | #[should_panic(expected = "mismatched types (i64 [... i1]) for phi")] |
| 159 | fn phi_with_mismatched_args_should_panic() { |
| 160 | let args = [ |
| 161 | ( |
| 162 | rir::Operand::Variable(rir::Variable { |
| 163 | variable_id: rir::VariableId(13), |
| 164 | ty: rir::Ty::Integer, |
| 165 | }), |
| 166 | rir::BlockId(3), |
| 167 | ), |
| 168 | ( |
| 169 | rir::Operand::Variable(rir::Variable { |
| 170 | variable_id: rir::VariableId(2), |
| 171 | ty: rir::Ty::Boolean, |
| 172 | }), |
| 173 | rir::BlockId(7), |
| 174 | ), |
| 175 | ]; |
| 176 | let inst = rir::Instruction::Phi( |
| 177 | args.to_vec(), |
| 178 | rir::Variable { |
| 179 | variable_id: rir::VariableId(0), |
| 180 | ty: rir::Ty::Integer, |
| 181 | }, |
| 182 | ); |
| 183 | let _ = &inst.to_qir(&rir::Program::default()); |
| 184 | } |
| 185 | |
| 186 | #[test] |
| 187 | #[should_panic(expected = "unsupported output type i64 for icmp")] |
| 188 | fn icmp_with_non_boolean_result_var_should_panic() { |
| 189 | let inst = rir::Instruction::Icmp( |
| 190 | rir::ConditionCode::Eq, |
| 191 | rir::Operand::Literal(rir::Literal::Integer(2)), |
| 192 | rir::Operand::Literal(rir::Literal::Integer(5)), |
| 193 | rir::Variable { |
| 194 | variable_id: rir::VariableId(0), |
| 195 | ty: rir::Ty::Integer, |
| 196 | }, |
| 197 | ); |
| 198 | let _ = inst.to_qir(&rir::Program::default()); |
| 199 | } |
| 200 | |