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: "jltz" 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: jltz 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 0xFFFFFFFF 46 jltz 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 -1 59 jltz label1 60 ldai 255 61 return # should be jumped over 62 label3: 63 - values: 64 - | 65 # Check jump to itself 66 ldai 0 67 loop: 68 jltz loop 69 bugid: ['3468'] 70 - values: 71 - | 72 # Check jump to itself 73 ldai -1 74 loop: 75 jltz loop 76 runner-options: [compile-only] 77 78 - file-name: "op_bounds" 79 isa: 80 instructions: 81 - sig: jltz 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 -1 96 jltz label # 2-byte instruction 97 ldai 1 ##*62 98 return 99 label: 100 ldai 0 101 return 102 - values: 103 - | 104 # Max backward jump for imm8, 1 + 2 + 61*2 + 1 + 2 = 128 bytes 105 jmp label2 106 label: 107 neg 108 ldai 61 109 subi 1 ##*61 110 return 111 label2: 112 ldai -1 113 jltz label 114 ldai 1 115 return 116 - values: 117 - | 118 # Max forward jump for imm16, 3 + 32760 + 4 = 32767 bytes 119 ldai -1 120 jltz label # 3-byte instruction 121 movi.64 v0, 0 ##*3276 122 neg 123 ldai 2 124 return 125 label: 126 ldai 0 127 return 128 - values: 129 - | 130 # Max backward jump for imm16, 1 + 4 + 32760 + 1 + 2 = 32768 bytes 131 jmp label2 132 label: 133 ldai 0 134 return 135 ldai 1 136 movi.64 v0, 0 ##*3276 137 return 138 label2: 139 ldai -1 140 jltz label 141 ldai 1 142 return 143 144 - file-name: "vals" 145 isa: 146 instructions: 147 - sig: jltz imm:i32 148 acc: in:i32 149 format: [op_imm_8, op_imm_16] 150 description: > 151 Check jump not occurs if `acc >= 0` 152 for different values in acc. 153 code-template: | 154 # 155 ldai *s 156 jltz label_bad 157 ldai %s 158 jltz label_good 159 label_bad: 160 ldai 255 161 return # should be jumped over 162 label_good: 163 check-type: exit-positive 164 template-cases: 165 - values: 166 - "-1" 167 exclude: [zero, max] 168 - values: 169 - "0x80000000" 170 exclude: [zero, one] 171 - values: 172 - "0xFFFFFFFF" 173 exclude: [one, max] 174 cases: 175 - values: 176 - "0" 177 id: zero 178 - values: 179 - "1" 180 id: one 181 - values: 182 - "0x7FFFFFFF" 183 id: max 184 185 - file-name: "type" 186 isa: 187 instructions: 188 - sig: jltz imm:i32 189 acc: in:i32 190 format: [op_imm_8, op_imm_16] 191 verification: 192 - acc_type 193 description: > 194 Check `jltz` with invalid types in acc. 195 tags: ['verifier'] 196 runner-options: ['verifier-failure', 'verifier-config'] 197 header-template: [] 198 code-template: | 199 # 200 .record A {} 201 .record panda.String <external> 202 .record panda.Object <external> 203 .function i32 main() { 204 %s 205 jltz label 206 ldai 255 207 label: 208 check-type: exit-positive 209 cases: 210 - values: 211 - lda.null 212 - values: 213 - ldai.64 0 214 - values: 215 - fldai 0 216 - values: 217 - fldai.64 0 218 - values: 219 - lda.type A 220 - values: 221 - lda.type A[] 222 - values: 223 - lda.type panda.String 224 - values: 225 - | 226 newobj v0, A 227 lda.obj v0 228 - values: 229 - | 230 newobj v0, panda.Object 231 lda.obj v0 232 - values: 233 - lda.str "0" 234 - values: 235 - | 236 # 237 movi v0, 10 238 newarr v0, v0, i32[] 239 lda.obj v0 240 241 - file-name: "outside_function" 242 isa: 243 instructions: 244 - sig: jltz imm:i32 245 acc: in:i32 246 format: [op_imm_8, op_imm_16] 247 verification: 248 - branch_target 249 description: > 250 Branch target should point to a beginning 251 of an instruction of the same method. 252 runner-options: ['compile-failure'] 253 header-template: [] 254 code-template: | 255 # 256 .function i32 f() { 257 label: 258 ldai 255 259 return 260 } 261 .function i32 main() { 262 ldai -1 263 jltz label 264 check-type: exit-positive 265 266 - file-name: "outside_try_catch_p" 267 isa: 268 instructions: 269 - sig: jltz imm:i32 270 acc: in:i32 271 format: [op_imm_8, op_imm_16] 272 description: Jump outside try/catch block. 273 bugid: ['3425'] 274 header-template: [] 275 code-template: | 276 .record panda.ArithmeticException <external> 277 .function i32 main() { 278 begin: 279 ldai -1 280 jltz outside 281 newobj v0, panda.ArithmeticException 282 throw v0 283 end: 284 ldai 1 285 return 286 catch_ae: 287 ldai 2 288 return 289 .catch panda.ArithmeticException, begin, end, catch_ae 290 ldai 3 291 return 292 outside: 293 check-type: exit-positive 294 295 - file-name: "outside_try_catch_j" 296 isa: 297 instructions: 298 - sig: jltz imm:i32 299 acc: in:i32 300 format: [op_imm_8, op_imm_16] 301 description: Jump outside try/catch block. 302 bugid: ['3425'] 303 header-template: [] 304 tags: ['irtoc_ignore'] 305 runner-options: ['use-pa'] 306 code-template: | 307 .language PandaAssembly 308 .record panda.NullPointerException <external> 309 .function i32 main() { 310 begin: 311 ldai -1 312 jltz outside 313 mov.null v0 314 throw v0 315 end: 316 ldai 1 317 return 318 catch_npe: 319 ldai 2 320 return 321 .catch panda.NullPointerException, begin, end, catch_npe 322 ldai 3 323 return 324 outside: 325 check-type: exit-positive 326 327 - file-name: uninitialized_regs 328 isa: 329 instructions: 330 - sig: jltz imm:i32 331 acc: in:i32 332 format: [op_imm_8, op_imm_16] 333 description: Check `jltz` with uninitialized acc. 334 tags: ['verifier'] 335 runner-options: ['verifier-failure', 'verifier-config'] 336 code-template: | 337 # 338 label: 339 jltz label 340 check-type: exit-positive 341 342 - file-name: "invalid_branch_target" 343 isa: 344 verification: 345 - branch_target 346 runner-options: [compile-failure] 347 description: Check 'jltz' instruction with invalid branch target. 348 header-template: [] 349 code-template: | 350 .record R {} 351 352 .function void R.ctor(R a0) <ctor> { 353 lbl_ctor: 354 return.void 355 } 356 357 .function void R.cctor() <cctor> { 358 lbl_cctor: 359 return.void 360 } 361 362 .function i32 foo(i32 a0, i32 a1) <static> { 363 lda a0 364 jltz %s 365 return 366 } 367 368 .function i32 bar() <static> { 369 lbl_bar: 370 ldai 1 371 return 372 } 373 374 .function i32 main() { 375 movi v0, 0 376 movi v1, 1 377 call.short foo, v0, v1 378 lbl_main: 379 check-type: exit-positive 380 cases: 381 - values: ["main"] 382 - values: ["foo"] 383 - values: ["bar"] 384 - values: ["baz"] 385 - values: ["R"] 386 - values: ["lbl_main"] 387 - values: ["lbl_bar"] 388 - values: ["lbl_ctor"] 389 - values: ["lbl_cctor"] 390 391 392 - file-name: "prohibited_branch_target" 393 isa: 394 verification: 395 - branch_target 396 runner-options: ['verifier-failure', 'verifier-config'] 397 tags: [verifier] 398 description: Check 'jltz' instruction with prohibited branch target. 399 header-template: [] 400 code-template: | 401 .record E1 {} 402 .record E2 {} 403 404 .function i32 main() { 405 ldai -1 406 jltz %s 407 408 begin: 409 ldai 0 410 return 411 mid: 412 ldai 1 413 return 414 end: 415 ldai 2 416 return 417 418 catch_E1_begin: 419 ldai 3 420 return 421 catch_E1_mid: 422 ldai 4 423 return 424 catch_E1_end: 425 ldai 5 426 return 427 428 catch_E2_begin: 429 ldai 6 430 return 431 catch_E2_mid: 432 ldai 7 433 return 434 catch_E2_end: 435 436 quit: 437 ldai 8 438 return 439 440 .catch E1, begin, end, catch_E1_begin, catch_E1_end 441 .catch E2, catch_E1_begin, catch_E1_end, catch_E2_begin, catch_E2_end 442 outside: 443 check-type: none 444 cases: 445 - values: ["begin"] 446 runner-options: ['verifier-only', 'verifier-config'] 447 - values: ["mid"] 448 runner-options: ['verifier-only', 'verifier-config'] 449 - values: ["end"] 450 runner-options: ['verifier-only', 'verifier-config'] 451 - values: ["quit"] 452 runner-options: ['verifier-only', 'verifier-config'] 453 - values: ["catch_E1_begin"] 454 - values: ["catch_E1_mid"] 455 - values: ["catch_E1_end"] 456 runner-options: ['verifier-only', 'verifier-config'] 457 - values: ["catch_E2_begin"] 458 - values: ["catch_E2_mid"] 459 - values: ["catch_E2_end"] 460 runner-options: ['verifier-only', 'verifier-config'] 461 - values: ["outside"] 462