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: 15 - name: java 16 template: | 17 .language Java 18 - name: aoobe_p 19 template: | 20 .record panda.ArrayIndexOutOfBoundsException <external> 21 .record R {} 22 - name: aoobe_j 23 template: | 24 .record java.lang.ArrayIndexOutOfBoundsException <external> 25 .record java.lang.String <external> 26 .record R {} 27 - name: npe_p 28 template: | 29 .record panda.NullPointerException <external> 30 - name: npe_j 31 template: | 32 .record java.lang.NullPointerException <external> 33tests: 34 - file-name: "ldarr.obj" 35 isa: 36 title: Load from array 37 description: > 38 Load an element from array using accumulator as an index and puts it into accumulator. 39 instructions: 40 - sig: ldarr.obj v:in:ref[] 41 acc: inout:i32->ref 42 format: [op_v_8] 43 44 commands: 45 - file-name: "reg_number" 46 isa: 47 description: > 48 Load an element from array using accumulator as an index and puts it into accumulator. 49 runner-options: [compile-only] 50 description: Check 'ldarr.obj' instruction with different register numbers. 51 header-template: [] 52 code-template: | 53 # 54 .function i32 main() { 55 ldarr.obj %s 56 check-type: exit-positive 57 cases: 58 - values: [v0] 59 - values: [v16] 60 - values: [v128] 61 - values: [v255] 62 - values: [v256] 63 runner-options: [compile-failure] 64 - values: [v65535] 65 runner-options: [compile-failure] 66 - case-template: | 67 # 68 .function void f1(i32 a0) { 69 ldarr.obj a0 # valid name of register 70 return.void 71 } 72 73 .function i32 main() { 74 movi v0, 0 75 call.short f1, v0 76 - case-template: | 77 # 78 .function void f1(i32 a0) { 79 ldarr.obj a1 # invalid name of register 80 return.void 81 } 82 83 .function i32 main() { 84 movi v0, 0 85 call.short f1, v0 86 runner-options: [compile-failure] 87 - values: [a0] 88 runner-options: [compile-failure] 89 - values: [a255] 90 runner-options: [compile-failure] 91 - values: [null] 92 runner-options: [compile-failure] 93 - values: [0] 94 runner-options: [compile-failure] 95 - values: [1.1] 96 runner-options: [compile-failure] 97 - values: ['2.2'] 98 runner-options: [compile-failure] 99 100 - file-name: uninitialized_acc 101 isa: 102 verification: 103 - acc_i32 104 description: Check 'ldarr.obj' with uninitialized accumulator 105 tags: ['verifier'] 106 runner-options: ['verifier-failure', 'verifier-debug-config'] 107 header-template: [] 108 code-template: | 109 # 110 .record R {} 111 .function void f1(R[] a0) { 112 ldarr.obj a0 113 return.void 114 } 115 .function i32 main() { 116 movi v1, 100 117 newarr v1, v1, R[] 118 call.short f1, v1 119 check-type: exit-positive 120 121 - file-name: uninitialized_reg 122 isa: 123 verification: 124 - v1_array_type 125 description: Check 'ldarr.obj' with uninitialized register 126 tags: ['verifier'] 127 runner-options: ['verifier-failure', 'verifier-debug-config'] 128 header-template: [] 129 code-template: | 130 # 131 .function i32 main() { 132 ldai 0 133 ldarr.obj v2 134 check-type: exit-positive 135 136 - file-name: uninitialized_acc_and_reg 137 isa: 138 verification: 139 - v1_array_type 140 - acc_i32 141 description: Check 'ldarr.obj' with uninitialized register and accumulator 142 tags: ['verifier'] 143 runner-options: ['verifier-failure', 'verifier-debug-config'] 144 header-template: [] 145 code-template: | 146 # 147 .function i32 main() { 148 ldarr.obj v2 149 check-type: exit-positive 150 151 - file-name: null_pointer_p 152 isa: 153 exceptions: 154 - x_null 155 description: Check 'ldarr.obj' behavior when array is null reference. 156 header-template: [npe_p] 157 bugid: ['3228'] 158 code-template: | 159 .record R {} 160 .function R[] get_null() { 161 lda.null 162 return.obj 163 } 164 .function i32 main() { 165 call.short get_null 166 sta.obj v0 167 ldai %s 168 begin: 169 ldarr.obj v0 170 end: 171 ldai 1 # Should not reach this line 172 return 173 174 catch_NPE: 175 ldai 0 # Expected panda.NullPointerException 176 return 177 178 catch_all: 179 ldai 2 # Unexpected exception, test failed 180 return 181 182 .catch panda.NullPointerException, begin, end, catch_NPE 183 .catchall begin, end, catch_all 184 check-type: none 185 cases: 186 - values: [0] 187 tags: ['tsan'] 188 - values: [1] 189 - values: [10] 190 - values: [128] 191 - values: [255] 192 - values: [65535] 193 tags: ['tsan'] 194 - values: [0x7FFFFFFF] 195 - values: [0xFFFFFFFF] 196 - values: [0x80000000] 197 198 - file-name: array_out_of_bound_exception_p 199 isa: 200 exceptions: 201 - x_bounds 202 description: Check 'ldarr.obj' behavior when index is out of array bounds. 203 header-template: [aoobe_p, main] 204 code-template: | 205 # 206 movi v0, *s 207 newarr v0, v0, %s 208 ldai *s 209 begin: 210 ldarr.obj v0 211 end: 212 ldai 1 # Should not reach this line 213 return 214 215 catch_AOOBE: 216 ldai 0 # Expected panda.ArrayIndexOutOfBoundsException 217 return 218 219 catch_all: 220 ldai 2 # Unexpected exception, test failed 221 return 222 223 .catch panda.ArrayIndexOutOfBoundsException, begin, end, catch_AOOBE 224 .catchall begin, end, catch_all 225 check-type: none 226 template-cases: 227 - values: ['R[]'] 228 - values: ['R[][][]'] 229 cases: 230 - values: [0, 0] 231 tags: ['tsan'] 232 - values: [0, 1] 233 - values: [10, -10] 234 - values: [10, 128] 235 - values: [255, 255] 236 - values: [254, 255] 237 - values: [65535, 65535] 238 tags: ['tsan'] 239 - values: [65535, 65536] 240 - values: [10, 0xFFFFFFFF] 241 - values: [256, 0xFFFFFFFE] 242 - values: [65536, 0xFFFFFFFD] 243 tags: ['tsan'] 244 - values: [0x100000, 0xFFFFFFFC] 245 - values: [10, 0x80000000] 246 - values: [256, 0x80000001] 247 - values: [65536, 0x80000002] 248 tags: ['tsan'] 249 - values: [0x100000, 0x80000003] 250 251 - file-name: "rejectable_primitive_types_p" 252 isa: 253 verification: 254 - v1_array_type 255 description: Check rejectable array of primitive types for ldarr.obj instruction in Panda Assembly context. 256 code-template: | 257 # 258 movi v0, 1 259 newarr v0, v0, %s 260 ldai 0 261 ldarr.obj v0 262 check-type: exit-positive 263 tags: ['verifier'] 264 runner-options: ['verifier-failure', 'verifier-debug-config'] 265 cases: 266 - values: ['u1[]'] 267 - values: ['i8[]'] 268 - values: ['u8[]'] 269 - values: ['i16[]'] 270 - values: ['u16[]'] 271 - values: ['i32[]'] 272 - values: ['u32[]'] 273 - values: ['i64[]'] 274 - values: ['u64[]'] 275 - values: ['f32[]'] 276 - values: ['f64[]'] 277 278 - file-name: "acceptable_types_p" 279 isa: 280 verification: 281 - v1_array_type 282 description: Check acceptable array types for ldarr.obj instruction in Panda Assembly context. 283 header-template: [] 284 code-template: | 285 .record R {} 286 .record panda.Object <external> 287 .record panda.String <external> 288 .record panda.Class <external> 289 .function i32 main() { 290 movi v0, 1 291 newarr v0, v0, %s 292 ldai 0 293 ldarr.obj v0 294 check-type: exit-positive 295 tags: ['verifier'] 296 runner-options: ['verifier-only', 'verifier-debug-config'] 297 cases: 298 - values: ['panda.Object[]'] 299 - values: ['panda.String[]'] 300 - values: ['panda.Class[]'] 301 - values: ['R[]'] 302 - values: ['panda.Object[][]'] 303 - values: ['panda.String[][]'] 304 - values: ['panda.Class[][]'] 305 - values: ['R[][]'] 306 - values: ['u1[][]'] 307 - values: ['u32[][]'] 308 - values: ['u64[][]'] 309 310 - file-name: "arr_type" 311 isa: 312 verification: 313 - v1_array_type 314 tags: ['verifier'] 315 runner-options: ['verifier-failure', 'verifier-debug-config'] 316 header-template: [] 317 code-template: | 318 # 319 .record A {} 320 .record panda.String <external> 321 .record panda.Object <external> 322 .function void panda.Object.ctor(panda.Object a0) <external,ctor> 323 .function i32 main() { 324 %s 325 ldai 0 326 ldarr.obj v0 327 check-type: exit-positive 328 description: Check 'ldarr.obj' with incorrect array type. 329 cases: 330 - values: 331 - movi v0, 0 332 - values: 333 - movi.64 v0, 0 334 - values: 335 - fmovi.64 v0, 0 336 - values: 337 - | 338 # 339 lda.type A 340 sta.obj v0 341 - values: 342 - | 343 # 344 lda.type A[] 345 sta.obj v0 346 - values: 347 - | 348 # 349 lda.type panda.String 350 sta.obj v0 351 - values: 352 - | 353 # 354 lda.type panda.String[] 355 sta.obj v0 356 - values: 357 - | 358 # 359 lda.type panda.Object 360 sta.obj v0 361 - values: 362 - | 363 # 364 lda.type panda.Object[] 365 sta.obj v0 366 - values: 367 - | 368 # 369 lda.str "string" 370 sta.obj v0 371 - values: 372 - | 373 # 374 initobj panda.Object.ctor 375 sta.obj v0 376 377 - file-name: "acc_type" 378 isa: 379 verification: 380 - acc_i32 381 tags: ['verifier'] 382 runner-options: ['verifier-failure', 'verifier-debug-config'] 383 header-template: [] 384 code-template: | 385 # 386 .record A {} 387 .record panda.String <external> 388 .record panda.Object <external> 389 .function void panda.Object.ctor(panda.Object a0) <external,ctor> 390 .function i32 main() { 391 movi v0, 1 392 newarr v0, v0, A[] 393 %s 394 ldarr.obj v0 395 check-type: exit-positive 396 description: Check 'ldarr.obj' with incorrect index type. 397 cases: 398 - values: 399 - lda.null 400 - values: 401 - ldai.64 0 402 - values: 403 - fldai.64 0 404 - values: 405 - lda.type A 406 - values: 407 - lda.type A[] 408 - values: 409 - lda.type panda.String 410 - values: 411 - lda.type panda.String[] 412 - values: 413 - lda.type panda.Object 414 - values: 415 - lda.type panda.Object[] 416 - values: 417 - lda.str "string" 418 - values: 419 - | 420 # 421 movi v1, 1 422 newarr v1, v1, panda.Object[] 423 lda.obj v1 424 - values: 425 - | 426 # 427 movi v1, 1 428 newarr v1, v1, panda.String[] 429 lda.obj v1 430 - values: 431 - initobj panda.Object.ctor 432 433 - file-name: "arr_acc_type" 434 isa: 435 verification: 436 - v1_array_type 437 - acc_i32 438 tags: ['verifier'] 439 runner-options: ['verifier-failure', 'verifier-debug-config'] 440 header-template: [] 441 code-template: | 442 # 443 .record A {} 444 .record panda.String <external> 445 .record panda.Object <external> 446 .function void panda.Object.ctor(panda.Object a0) <external,ctor> 447 .function i32 main() { 448 %s 449 *s 450 ldarr.obj v0 451 check-type: exit-positive 452 description: Check 'ldarr.obj' with incorrect register and accumulator types. 453 template-cases: 454 - values: 455 - movi v0, 0 456 - values: 457 - movi.64 v0, 0 458 - values: 459 - fmovi.64 v0, 0 460 - values: 461 - | 462 # 463 lda.type A 464 sta.obj v0 465 - values: 466 - | 467 # 468 lda.type A[] 469 sta.obj v0 470 - values: 471 - | 472 # 473 lda.type panda.String 474 sta.obj v0 475 - values: 476 - | 477 # 478 lda.type panda.String[] 479 sta.obj v0 480 - values: 481 - | 482 # 483 lda.type panda.Object 484 sta.obj v0 485 - values: 486 - | 487 # 488 lda.type panda.Object[] 489 sta.obj v0 490 - values: 491 - | 492 # 493 lda.str "string" 494 sta.obj v0 495 - values: 496 - | 497 # 498 movi v0, 1 499 newarr v0, v0, panda.Object[] 500 - values: 501 - | 502 # 503 movi v0, 1 504 newarr v0, v0, panda.String[] 505 - values: 506 - | 507 # 508 initobj panda.Object.ctor 509 sta.obj v0 510 cases: 511 - values: 512 - lda.null 513 - values: 514 - ldai.64 0 515 - values: 516 - fldai.64 0 517 - values: 518 - lda.type A 519 - values: 520 - lda.type A[] 521 - values: 522 - lda.type panda.String 523 - values: 524 - lda.type panda.String[] 525 - values: 526 - lda.type panda.Object 527 - values: 528 - lda.type panda.Object[] 529 - values: 530 - lda.str "string" 531 - values: 532 - | 533 # 534 movi v1, 1 535 newarr v1, v1, panda.Object[] 536 lda.obj v1 537 - values: 538 - | 539 # 540 movi v1, 1 541 newarr v1, v1, panda.String[] 542 lda.obj v1 543 - values: 544 - initobj panda.Object.ctor 545 546 - file-name: "read_all_values" 547 isa: 548 description: > 549 Load an element from array using accumulator as an index and puts it into accumulator. 550 description: Check ldarr.obj reads correct items from array of objects. 551 header-template: [] 552 check-type: exit-positive 553 code-template: | 554 %s 555 .function i32 main() { 556 movi v1, 0 # v1 - index 557 movi v0, *s 558 # v0 is array size 559 mov v2, v0 # v2 is size too 560 newarr v0, v0, A[] # v0 - testable array 561 fill_array: 562 lda v1 563 initobj A.ctor, v1 564 starr.obj v0, v1 # v0[v1] = acc 565 inci v1, 1 # v1 = v1 + 1 566 lda v1 567 jne v2, fill_array 568 569 movi v1, 0 # index 570 check_array: 571 lda v1 572 ldarr.obj v0 # acc = v0[acc] 573 sta.obj v3 # v3 = acc 574 call.virt.short A.cmp, v3, v1 575 jeqz ok 576 ldai 1 577 return 578 ok: 579 inci v1, 1 580 lda v1 581 jne v2, check_array 582 template-cases: 583 - values: 584 - | 585 # 586 .record A { 587 i32 fi32 588 } 589 .function void A.ctor(A a0, i32 a1) <ctor> { 590 lda a1 591 stobj a0, A.fi32 592 return.void 593 } 594 .function i32 A.cmp(A a0, i32 a1) { 595 ldobj a0, A.fi32 596 jne a1, exit_failure 597 ldai 0 598 return 599 exit_failure: 600 ldai 1 601 return 602 } 603 tags: ['tsan'] 604 - values: 605 - | 606 # 607 .record A { 608 A fA 609 } 610 .function void A.ctor(A a0, i32 a1) <ctor> { 611 lda.obj a0 612 stobj.obj a0, A.fA 613 return.void 614 } 615 .function i32 A.cmp(A a0, i32 a1) { 616 ldobj.obj a0, A.fA 617 jeq.obj a0, ret0 618 ldai 1 619 return 620 ret0: 621 ldai 0 622 return 623 } 624 cases: 625 - values: 626 - 10000 627 628 - file-name: "read_different_type_values_p" 629 isa: 630 description: > 631 Load an element from array using accumulator as an index and puts it into accumulator. 632 description: Check ldarr.obj reads correct items with various types from array of objects. 633 header-template: [] 634 check-type: exit-positive 635 code-template: | 636 %s 637 .function i32 main() { 638 movi v1, 1 639 newarr v0, v1, %s # v0 - testable array 640 movi v1, 0 # v1 - index = 0 641 642 check_null: 643 lda v1 644 ldarr.obj v0 # acc = v0[acc] 645 jeqz.obj fill_array 646 ldai 1 647 return 648 649 fill_array: 650 %s 651 sta.obj v10 # v10 - saved object ref 652 starr.obj v0, v1 # v0[v1] = acc 653 654 check_ref: 655 lda v1 656 ldarr.obj v0 # acc = v0[acc] 657 jeq.obj v10, ok 658 ldai 2 659 return 660 ok: 661 cases: 662 - values: 663 - .record A {} 664 - A[] 665 - lda.null 666 - values: 667 - | 668 .record A {} 669 .function void A.ctor(A a0) <ctor> { 670 return.void 671 } 672 - A[] 673 - initobj A.ctor 674 tags: ['tsan'] 675 - values: 676 - | 677 .record panda.Class <external> 678 .record A {} 679 - panda.Class[] 680 - lda.type A 681 bugid: ['3219'] 682 - values: 683 - .record panda.String <external> 684 - panda.String[] 685 - lda.str "test string" 686 - values: 687 - | 688 .record panda.Object <external> 689 .record A {} 690 .function void A.ctor(A a0) <ctor> { 691 return.void 692 } 693 - panda.Object[] 694 - initobj A.ctor 695 tags: ['tsan'] 696 - values: 697 - .record A {} 698 - A[][] 699 - | 700 # 701 movi v4, 10 702 newarr v4, v4, A[] 703 lda.obj v4 704 705