1# Copyright (c) 2021-2022 Huawei Device Co., Ltd. 2# Licensed under the Apache License, Version 2.0 (the "License"); 3# you may not use this file except in compliance with the License. 4# You may obtain a copy of the License at 5# 6# http://www.apache.org/licenses/LICENSE-2.0 7# 8# Unless required by applicable law or agreed to in writing, software 9# distributed under the License is distributed on an "AS IS" BASIS, 10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11# See the License for the specific language governing permissions and 12# limitations under the License. 13 14definitions: [] 15tests: 16 - file-name: "jmp" 17 isa: 18 title: Unconditional jump 19 description: > 20 Unconditionally transfer execution to an instruction at offset bytes from the beginning of the current 21 instruction. Offset is sign extended to the size of instruction address. 22 verification: 23 - branch_target 24 exceptions: 25 - x_none 26 commands: 27 - file-name: "op_none" 28 isa: 29 instructions: 30 - sig: jmp imm:i32 31 acc: none 32 format: [op_imm_8, op_imm_16, op_imm_32] 33 description: Check execution is transferred, jump forward, backward, jump on current instruction. 34 code-template: | 35 # 36 %s 37 check-type: exit-positive 38 tags: ['tsan'] 39 cases: 40 - values: 41 - | 42 # Jump forward 43 jmp l1 44 lda.null 45 l1: 46 lda.null 47 48 - values: 49 - | 50 # 51 jmp l1 52 ldai 255 ##*255 53 # should not be here 54 return 55 l1: 56 57 - values: 58 - | 59 # 60 jmp l1 61 lda.null ##*256 62 l1: 63 64 - values: 65 - | 66 # 67 jmp l1 68 ldai 255 ##*32767 69 # should not be here 70 return 71 l1: 72 73 - values: 74 - | 75 # 76 jmp l1 77 ldai 255 ##*65536 78 # should not be here 79 return 80 l1: 81 82 - values: 83 - | 84 # 85 jmp l1 86 l2: jmp l3 87 l4: jmp l5 88 l3: jmp l4 89 l1: jmp l2 90 l5: 91 92 - values: 93 - | 94 # Jump back 95 jmp l1 96 l3: 97 lda.null 98 jmp l2 99 l1: 100 jmp l3 101 l2: 102 103 - values: 104 - | 105 # Jump back 106 jmp l1 107 l3: 108 lda.null ##*255 109 jmp l2 110 ldai 255 111 # should not be here 112 return 113 l1: 114 jmp l3 115 l2: 116 117 - values: 118 - | 119 # Jump back 120 jmp l1 121 l3: 122 lda.null ##*256 123 jmp l2 124 l1: 125 jmp l3 126 l2: 127 128 - values: 129 - | 130 # Jump back 131 jmp l1 132 l3: 133 lda.null ##*32767 134 jmp l2 135 l1: 136 jmp l3 137 l2: 138 description: Check jump with large offset. 139 140 - values: 141 - | 142 # Jump back 143 jmp l1 144 l3: 145 lda.null ##*65536 146 jmp l2 147 ldai 255 148 # should not be here 149 return 150 l1: 151 jmp l3 152 l2: 153 description: Check jump with large offset. 154 155 - values: 156 - | 157 # Jump back 158 loop: 159 jmp loop 160 runner-options: [compile-only] 161 162 - values: 163 - | 164 # Jump outside function 165 jmp loop 166 } 167 .function u1 some_fnc() { 168 loop: 169 runner-options: [compile-failure] 170 171 - values: 172 - | 173 # 174 call jmp_wrap 175 ldai 0 176 return 177 } 178 179 .function u1 jmp_target() { 180 label: 181 return 182 } 183 .function u1 jmp_wrap() { 184 # Jump back, other function 185 jmp label 186 } 187 case-check-type: empty 188 runner-options: [compile-failure] 189 190 - values: 191 - | 192 # 193 call jmp_wrap 194 ldai 0 195 return 196 } 197 198 .function u1 jmp_wrap() { 199 # Jump forward, other function 200 jmp label 201 202 } 203 .function u1 jmp_target() { 204 label: 205 return 206 } 207 case-check-type: empty 208 runner-options: [compile-failure] 209 210 - values: 211 - | 212 # Check jump out of bounds of method body is not allowed. 213 jmp label 214 ldai 0 215 return 216 label: 217 } 218 case-check-type: empty 219 runner-options: ['verifier-failure', 'verifier-config'] 220 tags: ['verifier'] 221 222 - file-name: "outside_try_catch_p" 223 isa: 224 instructions: 225 - sig: jmp imm:i32 226 acc: none 227 format: [op_imm_8, op_imm_16, op_imm_32] 228 description: Jump outside try/catch block. 229 bugid: ['3425'] 230 header-template: [] 231 code-template: | 232 .record panda.ArithmeticException <external> 233 .function i32 main() { 234 begin: 235 jmp outside 236 newobj v0, panda.ArithmeticException 237 throw v0 238 end: 239 ldai 1 240 return 241 catch_ae: 242 ldai 2 243 return 244 .catch panda.ArithmeticException, begin, end, catch_ae 245 ldai 3 246 return 247 outside: 248 check-type: exit-positive 249 250 - file-name: "outside_try_catch_j" 251 isa: 252 instructions: 253 - sig: jmp imm:i32 254 acc: none 255 format: [op_imm_8, op_imm_16, op_imm_32] 256 description: Jump outside try/catch block. 257 bugid: ['3425'] 258 header-template: [] 259 runner-options: ['use-pa'] 260 code-template: | 261 .language PandaAssembly 262 .record panda.NullPointerException <external> 263 .function i32 main() { 264 begin: 265 jmp outside 266 mov.null v0 267 throw v0 268 end: 269 ldai 1 270 return 271 catch_npe: 272 ldai 2 273 return 274 .catch panda.NullPointerException, begin, end, catch_npe 275 ldai 3 276 return 277 outside: 278 check-type: exit-positive 279