1# Copyright (c) 2021 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: "jeqz" 17 isa: 18 title: Conditional compared to zero jump 19 description: > 20 Transfer execution to an instruction at offset bytes 21 from the beginning of the current instruction 22 if signed 32-bit integer in accumulator compares with 0 as specified. 23 Offset is sign extended to the size of instruction address. 24 exceptions: 25 - x_none 26 commands: 27 28 - file-name: "op" 29 isa: 30 instructions: 31 - sig: jeqz imm:i32 32 acc: in:i32 33 format: [op_imm_8, op_imm_16] 34 description: > 35 Check jump occurs or not occurs, depending on `acc == 0` condition 36 for forward, backward, or current cases. 37 code-template: | 38 # 39 %s 40 check-type: exit-positive 41 cases: 42 - values: 43 - | 44 # Check forward jump 45 ldai 0 46 jeqz label 47 ldai 255 ##*65536 48 return # should be jumped over 49 label: 50 - values: 51 - | 52 # Check backward jump 53 jmp label2 54 label1: 55 jmp label3 56 ldai 255 ##*65536 57 label2: 58 ldai 0 59 jeqz label1 60 ldai 255 61 return # should be jumped over 62 label3: 63 - values: 64 - | 65 # Check jump to itself 66 ldai 1 67 loop: 68 jeqz loop 69 bugid: ['3468'] 70 - values: 71 - | 72 # Check jump to itself 73 ldai 0 74 loop: 75 jeqz loop 76 runner-options: [compile-only] 77 78 - file-name: "op_bounds" 79 isa: 80 instructions: 81 - sig: jeqz imm:i32 82 acc: in:i32 83 format: [op_imm_8, op_imm_16] 84 description: > 85 Check jump occurs or not occurs, depending on `acc == 0` condition 86 for forward and backward cases. 87 code-template: | 88 # 89 %s 90 check-type: none 91 cases: 92 - values: 93 - | 94 # Max forward jump for imm8, 2 + 124 + 1 = 127 bytes 95 ldai 0 96 jeqz label # 2-byte instruction 97 neg 98 ldai 2 ##*62 99 label: 100 return 101 - values: 102 - | 103 # Max backward jump for imm8, 1 + 2 + 2*61 + 1 + 2 = 128 bytes 104 jmp label2 105 label: 106 neg 107 ldai 61 108 subi 1 ##*61 109 return 110 label2: 111 ldai 0 112 jeqz label 113 ldai 1 114 return 115 - values: 116 - | 117 # Max forward jump for imm16, 3 + 32760 + 4 = 32767 bytes 118 ldai 0 119 jeqz label # 3-byte instruction 120 movi.64 v0, 0 ##*3276 121 ldai 1 122 ldai 1 123 label: 124 return 125 - values: 126 - | 127 # Max backward jump for imm16, 1 + 4 + 32760 + 1 + 2 = 32768 bytes 128 jmp label2 129 label: 130 return 131 ldai 2 132 ldai 2 133 movi.64 v0, 0 ##*3276 134 return 135 label2: 136 ldai 0 137 jeqz label 138 ldai 1 139 return 140 141 - file-name: "vals" 142 isa: 143 instructions: 144 - sig: jeqz imm:i32 145 acc: in:i32 146 format: [op_imm_8, op_imm_16] 147 description: > 148 Check jump not occurs if `acc != 0` 149 for different values in acc. 150 code-template: | 151 # 152 ldai %s 153 jeqz label_bad 154 ldai 0 155 jeqz label_good 156 label_bad: 157 ldai 255 158 return # should be jumped over 159 label_good: 160 check-type: exit-positive 161 cases: 162 - values: 163 - "-1" 164 - values: 165 - "1" 166 - values: 167 - "0x7FFFFFFF" 168 - values: 169 - "0x80000000" 170 - values: 171 - "0xFFFFFFFF" 172 173 - file-name: "type" 174 isa: 175 instructions: 176 - sig: jeqz imm:i32 177 acc: in:i32 178 format: [op_imm_8, op_imm_16] 179 verification: 180 - acc_type 181 description: > 182 Check jeqz with invalid types in acc. 183 tags: ['verifier'] 184 runner-options: ['verifier-failure', 'verifier-debug-config'] 185 header-template: [] 186 code-template: | 187 # 188 .record A {} 189 .record panda.String <external> 190 .record panda.Object <external> 191 .function i32 main() { 192 %s 193 jeqz label 194 ldai 255 195 label: 196 check-type: exit-positive 197 cases: 198 - values: 199 - lda.null 200 - values: 201 - ldai.64 0 202 - values: 203 - fldai.64 0 204 - values: 205 - lda.type A 206 - values: 207 - lda.type A[] 208 - values: 209 - lda.type panda.String 210 - values: 211 - | 212 newobj v0, A 213 lda.obj v0 214 - values: 215 - | 216 newobj v0, panda.Object 217 lda.obj v0 218 - values: 219 - lda.str "0" 220 - values: 221 - | 222 # 223 movi v0, 10 224 newarr v0, v0, i32[] 225 lda.obj v0 226 227 - file-name: "outside_function" 228 isa: 229 instructions: 230 - sig: jeqz imm:i32 231 acc: in:i32 232 format: [op_imm_8, op_imm_16] 233 verification: 234 - branch_target 235 description: > 236 Branch target should point to a beginning 237 of an instruction of the same method. 238 runner-options: ['compile-failure'] 239 header-template: [] 240 code-template: | 241 # 242 .function i32 f() { 243 label: 244 ldai 255 245 return 246 } 247 .function i32 main() { 248 ldai 0 249 jeqz label 250 check-type: exit-positive 251 252 - file-name: "outside_try_catch_p" 253 isa: 254 instructions: 255 - sig: jeqz imm:i32 256 acc: in:i32 257 format: [op_imm_8, op_imm_16] 258 description: Jump outside try/catch block. 259 bugid: ['3425'] 260 header-template: [] 261 code-template: | 262 .record panda.ArithmeticException <external> 263 .function i32 main() { 264 begin: 265 ldai 0 266 jeqz outside 267 newobj v0, panda.ArithmeticException 268 throw v0 269 end: 270 ldai 1 271 return 272 catch_ae: 273 ldai 2 274 return 275 .catch panda.ArithmeticException, begin, end, catch_ae 276 ldai 3 277 return 278 outside: 279 check-type: exit-positive 280 281 - file-name: uninitialized_regs 282 isa: 283 instructions: 284 - sig: jeqz imm:i32 285 acc: in:i32 286 format: [op_imm_8, op_imm_16] 287 description: Check `jeqz` with uninitialized acc. 288 tags: ['verifier'] 289 runner-options: ['verifier-failure', 'verifier-debug-config'] 290 code-template: | 291 # 292 label: 293 jeqz label 294 check-type: exit-positive 295 296 - file-name: "invalid_branch_target" 297 isa: 298 verification: 299 - branch_target 300 runner-options: [compile-failure] 301 description: Check 'jeqz' instruction with invalid branch target. 302 header-template: [] 303 code-template: | 304 .record R {} 305 306 .function void R.ctor(R a0) <ctor> { 307 lbl_ctor: 308 return.void 309 } 310 311 .function void R.cctor() <cctor> { 312 lbl_cctor: 313 return.void 314 } 315 316 .function i32 foo(i32 a0, i32 a1) <static> { 317 lda a0 318 jeqz %s 319 return 320 } 321 322 .function i32 bar() <static> { 323 lbl_bar: 324 ldai 1 325 return 326 } 327 328 .function i32 main() { 329 movi v0, 0 330 movi v1, 1 331 call.short foo, v0, v1 332 lbl_main: 333 check-type: exit-positive 334 cases: 335 - values: ["main"] 336 - values: ["foo"] 337 - values: ["bar"] 338 - values: ["baz"] 339 - values: ["R"] 340 - values: ["lbl_main"] 341 - values: ["lbl_bar"] 342 - values: ["lbl_ctor"] 343 - values: ["lbl_cctor"] 344 345 346 - file-name: "prohibited_branch_target" 347 isa: 348 verification: 349 - branch_target 350 runner-options: ['verifier-failure', 'verifier-debug-config'] 351 tags: [verifier] 352 description: Check 'jeqz' instruction with prohibited branch target. 353 header-template: [] 354 code-template: | 355 .record E1 {} 356 .record E2 {} 357 358 .function i32 main() { 359 ldai 0 360 jeqz %s 361 362 begin: 363 ldai 0 364 return 365 mid: 366 ldai 1 367 return 368 end: 369 ldai 2 370 return 371 372 catch_E1_begin: 373 ldai 3 374 return 375 catch_E1_mid: 376 ldai 4 377 return 378 catch_E1_end: 379 ldai 5 380 return 381 382 catch_E2_begin: 383 ldai 6 384 return 385 catch_E2_mid: 386 ldai 7 387 return 388 catch_E2_end: 389 390 quit: 391 ldai 8 392 return 393 394 .catch E1, begin, end, catch_E1_begin, catch_E1_end 395 .catch E2, catch_E1_begin, catch_E1_end, catch_E2_begin, catch_E2_end 396 outside: 397 check-type: none 398 cases: 399 - values: ["begin"] 400 runner-options: ['verifier-only', 'verifier-debug-config'] 401 - values: ["mid"] 402 runner-options: ['verifier-only', 'verifier-debug-config'] 403 - values: ["end"] 404 runner-options: ['verifier-only', 'verifier-debug-config'] 405 - values: ["quit"] 406 runner-options: ['verifier-only', 'verifier-debug-config'] 407 - values: ["catch_E1_begin"] 408 - values: ["catch_E1_mid"] 409 - values: ["catch_E1_end"] 410 runner-options: ['verifier-only', 'verifier-debug-config'] 411 - values: ["catch_E2_begin"] 412 - values: ["catch_E2_mid"] 413 - values: ["catch_E2_end"] 414 runner-options: ['verifier-only', 'verifier-debug-config'] 415 - values: ["outside"] 416