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: 15 - name: pandasm_header 16 template: | 17 .language PandaAssembly 18 .record panda.Object <external> 19 .record Q {} 20 .record R { 21 u1 fu1 22 u8 fu8 23 i8 fi8 24 u16 fu16 25 i16 fi16 26 u32 fu32 27 i32 fi32 28 u64 fu64 29 i64 fi64 30 f32 ff32 31 f64 ff64 32 i32[] fi32Array 33 Q fQ 34 Q[] fQArray 35 panda.Object fObj 36 panda.Object[] fObjArray 37 } 38 39 - name: PandaAssembly_header 40 template: | 41 .language PandaAssembly 42 .record panda.Object <external> 43 .record I <panda.interface> {} 44 .record Q <panda.implements=I> {} 45 .record R <panda.extends=Q> { 46 u1 fu1 47 i8 fi8 48 u16 fu16 49 i16 fi16 50 i32 fi32 51 i64 fi64 52 f32 ff32 53 f64 ff64 54 # objects 55 i32[] fi32Array 56 Q fQ 57 Q[] fQArray 58 R fR 59 R[] fRArray 60 I fI 61 I[] fIArray 62 panda.Object fObj 63 panda.Object[] fObjArray 64 } 65 66 67tests: 68 - file-name: "stobj.v.64" 69 isa: 70 title: Store register content into object field 71 description: > 72 Store register content into object field by field_id. For non-object variant the size of actually stored 73 value is determined by field_id, other register bits are discarded. 74 instructions: 75 - sig: stobj.v.64 v1:in:b64, v2:in:ref, field_id 76 acc: none 77 format: [op_v1_4_v2_4_id_16] 78 commands: 79 80 - file-name: "check_if_regs_initialized_p" 81 description: Check that verifier reports error if a register is not initialized in PandaAssembly context. 82 isa: 83 description: Store register content into object field by field_id. 84 header-template: ['pandasm_header'] 85 check-type: exit-positive 86 tags: ['verifier'] 87 runner-options: ['verifier-failure', 'verifier-config'] 88 code-template: | 89 90 %s 91 92 .function i32 main() { 93 newobj v0, R 94 fmovi.64 v1, 1.1 95 %s 96 cases: 97 - values: 98 - "" 99 - stobj.v.64 v2, v0, R.ff64 100 - values: 101 - "" 102 - stobj.v.64 v1, v2, R.ff64 103 - values: 104 - | 105 # v0 (value) not initialized in the frame 106 .function void check(R a0) { 107 stobj.v.64 v0, a0, R.ff64 108 return.void 109 } 110 - call.short check, v0 111 - values: 112 - | 113 # v0 (object) not initialized in the frame 114 .function void check(f64 a0) { 115 stobj.v.64 a0, v0, R.ff64 116 return.void 117 } 118 - call.short check, v1 119 120 121 - file-name: "check_if_regs_initialized_j" 122 description: Check that verifier reports error if a register is not initialized in PandaAssembly context. 123 isa: 124 description: Store register content into object field by field_id. 125 header-template: ['PandaAssembly_header'] 126 check-type: exit-positive 127 tags: [verifier, pa-verifier] 128 runner-options: ['use-pa', 'verifier-failure', 'verifier-config'] 129 code-template: | 130 131 %s 132 133 .function i32 main() { 134 newobj v0, R 135 fmovi.64 v1, 1.1 136 %s 137 cases: 138 - values: 139 - "" 140 - stobj.v.64 v2, v0, R.ff64 141 - values: 142 - "" 143 - stobj.v.64 v1, v2, R.ff64 144 - values: 145 - | 146 # v0 (value) not initialized in the frame 147 .function void check(R a0) { 148 stobj.v.64 v0, a0, R.ff64 149 return.void 150 } 151 - call.short check, v0 152 - values: 153 - | 154 # v0 (object) not initialized in the frame 155 .function void check(f64 a0) { 156 stobj.v.64 a0, v0, R.ff64 157 return.void 158 } 159 - call.short check, v1 160 161 162 - file-name: "with_null_ref_p" 163 description: Check that NullPointerException is thrown if object ref is null in PandaAssembly context. 164 isa: 165 exceptions: 166 - x_null 167 header-template: ['pandasm_header'] 168 check-type: empty 169 tags: ['irtoc_ignore'] 170 code-template: | 171 .record panda.NullPointerException <external> 172 173 .function R get_null() { 174 lda.null 175 return.obj 176 } 177 178 .function i32 main() { 179 call.short get_null 180 sta.obj v0 181 %s 182 try_begin: 183 stobj.v.64 v1, v0, %s 184 ldai 1 185 return 186 try_end: 187 ldai 0 188 return 189 .catch panda.NullPointerException, try_begin, try_end, try_end 190 } 191 cases: 192 - values: 193 - movi.64 v1, -1 194 - R.fi64 195 - values: 196 - movi.64 v1, 1 197 - R.fu64 198 - values: 199 - fmovi.64 v1, 1.1 200 - R.ff64 201 202 203 - file-name: "with_null_ref_j" 204 description: Check that NullPointerException is thrown if object ref is null in PandaAssembly context. 205 isa: 206 exceptions: 207 - x_null 208 header-template: ['PandaAssembly_header'] 209 tags: ['irtoc_ignore'] 210 runner-options: ['use-pa'] 211 check-type: empty 212 code-template: | 213 .record panda.NullPointerException <external> 214 215 .function R get_null() { 216 lda.null 217 return.obj 218 } 219 220 .function i32 main() { 221 call.short get_null 222 sta.obj v0 223 %s 224 try_begin: 225 stobj.v.64 v1, v0, %s 226 ldai 1 227 return 228 try_end: 229 ldai 0 230 return 231 .catch panda.NullPointerException, try_begin, try_end, try_end 232 } 233 cases: 234 - values: 235 - movi.64 v1, -1 236 - R.fi64 237 - values: 238 - fmovi.64 v1, 1.1 239 - R.ff64 240 241 242 - file-name: "with_non_object_ref_p" 243 description: > 244 Check that verifier reports error when the 2nd operand is not a ref to an 245 object (other than array) in PandaAssembly context. 246 isa: 247 verification: 248 - v2_object 249 header-template: ['pandasm_header'] 250 check-type: exit-positive 251 tags: ['verifier'] 252 runner-options: ['verifier-failure', 'verifier-config'] 253 code-template: | 254 .function i32 main() { 255 *s 256 movi.64 v1, 1 257 stobj.v.64 v1, v0, %s 258 template-cases: 259 - values: ['R.fi64'] 260 - values: ['R.fu64'] 261 bugid: ['5502'] 262 ignore: true 263 - values: ['R.ff64'] 264 cases: 265 - values: 266 - movi v0, 0 267 - values: 268 - movi v0, 1 269 - values: 270 - movi.64 v0, 0x00 271 - values: 272 - movi.64 v0, 0xCAFECAFECAFECAFE 273 - values: 274 - fmovi.64 v0, 0.0 275 - values: 276 - fmovi.64 v0, 6.62607015 277 - values: 278 - | 279 # 280 movi v1, 10 281 newarr v0, v1, panda.Object[] 282 283 284 - file-name: "with_non_object_ref_j" 285 description: > 286 Check that verifier reports error when the 2nd operand is not a ref to an 287 object (other than array) in PandaAssembly context. 288 isa: 289 verification: 290 - v2_object 291 header-template: ['PandaAssembly_header'] 292 check-type: exit-positive 293 tags: [verifier, pa-verifier] 294 runner-options: ['verifier-failure', 'verifier-config'] 295 code-template: | 296 .function i32 main() { 297 *s 298 fmovi.64 v1, 3.1415 299 stobj.v.64 v1, v0, %s 300 template-cases: 301 - values: ['R.fi64'] 302 bugid: ['5502'] 303 ignore: true 304 - values: ['R.ff64'] 305 bugid: ['5502'] 306 ignore: true 307 cases: 308 - values: 309 - movi v0, 0 310 - values: 311 - movi v0, 1 312 - values: 313 - movi.64 v0, 0x00 314 - values: 315 - movi.64 v0, 0xCAFECAFECAFECAFE 316 - values: 317 - fmovi.64 v0, 0.0 318 - values: 319 - fmovi.64 v0, 6.62607015 320 - values: 321 - | 322 # 323 movi v1, 10 324 newarr v0, v1, panda.Object[] 325 326 327 - file-name: "with_static_field_id_p" 328 description: > 329 Check that verifier reports error when the field doesn't resolve to a non-static 330 valid object field in PandaAssembly context. 331 isa: 332 verification: 333 - field_id_non_static 334 header-template: [] 335 check-type: exit-positive 336 runner-options: ['compile-failure'] 337 code-template: | 338 .record W { 339 i64 static_field <static> 340 } 341 .record random_record { 342 i64 random_field 343 i64 random_static_field <static> 344 } 345 .function void random_function() { 346 return.void 347 } 348 349 .function i32 main() { 350 newobj v0, W 351 movi.64 v1, 1 352 stobj.v.64 v1, v0, %s 353 cases: 354 - values: 355 - W.static_field 356 runner-options: ['verifier-failure', 'verifier-config'] 357 tags: ['verifier'] 358 - values: 359 - random_record 360 - values: 361 - random_function 362 - values: 363 - W.field_not_exists 364 - values: 365 - random_record.random_field 366 runner-options: ['verifier-failure', 'verifier-config'] 367 tags: ['verifier'] 368 - values: 369 - random_record.random_static_field 370 runner-options: ['verifier-failure', 'verifier-config'] 371 tags: ['verifier'] 372 - values: 373 - 0 374 - values: 375 - -1.1 376 - values: 377 - "null" 378 - values: 379 - "\"abc\"" 380 381 382 - file-name: "with_static_field_id_j" 383 description: > 384 Check that verifier reports error when the field doesn't resolve to a non-static 385 valid object field in PandaAssembly context. 386 isa: 387 verification: 388 - field_id_non_static 389 header-template: [] 390 check-type: exit-positive 391 runner-options: ['use-pa', 'verifier-failure', 'verifier-config'] 392 tags: [verifier, pa-verifier] 393 code-template: | 394 .language PandaAssembly 395 .record A { 396 i64 a_field <static, panda.access=public> 397 } 398 .record B <panda.extends=A> { 399 i64 b_field <static, panda.access=public> 400 } 401 .record C <panda.extends=B> { 402 i64 c_field <static, panda.access=public> 403 } 404 405 .function i32 main() { 406 newobj v0, %s 407 movi.64 v2, 1 408 stobj.v.64 v2, v0, %s 409 cases: 410 - values: 411 - C 412 - C.c_field 413 - values: 414 - C 415 - B.b_field 416 - values: 417 - C 418 - A.a_field 419 - values: 420 - B 421 - B.a_field 422 runner-options: ['compile-failure'] 423 - values: 424 - B 425 - B.c_field 426 runner-options: ['compile-failure'] 427 428 429 - file-name: "with_wrong_field_size_p" 430 description: > 431 Check that verifier reports error when the field resolves to a field with size 432 that is not corresponding to bytecode in PandaAssembly context. 433 isa: 434 verification: 435 - field_id_size 436 header-template: ['pandasm_header'] 437 check-type: exit-positive 438 tags: ['verifier'] 439 runner-options: ['verifier-failure', 'verifier-config'] 440 code-template: | 441 .function i32 main() { 442 newobj v0, R 443 %s 444 stobj.v.64 v1, v0, %s 445 cases: 446 - values: 447 - movi.64 v1, 0 448 - R.fu1 449 - values: 450 - movi.64 v1, 0 451 - R.fu8 452 - values: 453 - movi.64 v1, 0 454 - R.fi8 455 - values: 456 - fmovi.64 v1, 0 457 - R.fu16 458 - values: 459 - movi.64 v1, 0 460 - R.fi16 461 - values: 462 - movi.64 v1, 0 463 - R.fu32 464 - values: 465 - movi.64 v1, 0 466 - R.fi32 467 - values: 468 - fmovi.64 v1, 0.0 469 - R.ff32 470 bugid: ['6094'] 471 - values: 472 - movi.64 v1, 0 473 - R.fObj 474 - values: 475 - fmovi.64 v1, 0 476 - R.fObjArray 477 - values: 478 - movi.64 v1, 0 479 - R.fi32Array 480 481 482 - file-name: "with_wrong_field_size_j" 483 description: > 484 Check that verifier reports error when the field resolves to a field with size 485 that is not corresponding to bytecode in PandaAssembly context. 486 isa: 487 verification: 488 - field_id_size 489 header-template: ['PandaAssembly_header'] 490 check-type: exit-positive 491 tags: [verifier, pa-verifier] 492 runner-options: ['use-pa', 'verifier-failure', 'verifier-config'] 493 code-template: | 494 .function i32 main() { 495 newobj v0, R 496 %s 497 stobj.v.64 v1, v0, %s 498 cases: 499 - values: 500 - movi.64 v1, 0 501 - R.fu1 502 - values: 503 - movi.64 v1, -1 504 - R.fi8 505 - values: 506 - movi.64 v1, 0 507 - R.fu16 508 - values: 509 - movi.64 v1, -1 510 - R.fi16 511 - values: 512 - movi.64 v1, -1 513 - R.fi32 514 - values: 515 - fmovi.64 v1, 0.123 516 - R.ff32 517 bugid: ['6094'] 518 - values: 519 - movi.64 v1, 0 520 - R.fObj 521 - values: 522 - fmovi.64 v1, 0.0 523 - R.fObjArray 524 - values: 525 - movi.64 v1, 0 526 - R.fi32Array 527 - values: 528 - fmovi.64 v1, 0.0 529 - R.fI 530 - values: 531 - movi.64 v1, 0 532 - R.fIArray 533 534 535 - file-name: "with_wrong_reg_type_p" 536 description: > 537 Check that verifier reports error when the register contains a value of type not corresponding 538 to the bytecode in PandaAssembly context. 539 isa: 540 verification: 541 - v1_type 542 header-template: ['pandasm_header'] 543 check-type: exit-positive 544 tags: ['verifier'] 545 runner-options: ['verifier-failure', 'verifier-config'] 546 code-template: | 547 .function i32 main() { 548 newobj v0, R 549 %s 550 stobj.v.64 v1, v0, %s 551 cases: 552 # u64 553 - values: 554 - movi v1, 0 555 - R.fu64 556 - values: 557 - movi v1, 0xCAFECAFE 558 - R.fu64 559 - values: 560 - fmovi v1, 1.1 561 - R.fu64 562 - values: 563 - fmovi.64 v1, 1.1 564 - R.fu64 565 - values: 566 - mov.null v1 567 - R.fu64 568 - values: 569 - newobj v1, Q 570 - R.fu64 571 - values: 572 - | 573 # 574 movi v1, 10 575 newarr v1, v1, panda.Object[] 576 - R.fu64 577 # i64 578 - values: 579 - movi v1, 0 580 - R.fi64 581 - values: 582 - movi v1, 0xCAFECAFE 583 - R.fi64 584 - values: 585 - fmovi v1, 1.1 586 - R.fi64 587 - values: 588 - fmovi.64 v1, 1.1 589 - R.fi64 590 - values: 591 - mov.null v1 592 - R.fi64 593 - values: 594 - newobj v1, Q 595 - R.fi64 596 - values: 597 - | 598 # 599 movi v1, 10 600 newarr v1, v1, panda.Object[] 601 - R.fi64 602 # f64 603 - values: 604 - movi v1, 0 605 - R.ff64 606 - values: 607 - movi v1, 0xCAFECAFE 608 - R.ff64 609 - values: 610 - movi.64 v1, 1 611 - R.ff64 612 - values: 613 - fmovi v1, 1.1 614 - R.ff64 615 bugid: ['6094'] 616 - values: 617 - mov.null v1 618 - R.ff64 619 - values: 620 - newobj v1, Q 621 - R.ff64 622 - values: 623 - | 624 # 625 movi v1, 10 626 newarr v1, v1, panda.Object[] 627 - R.ff64 628 629 630 - file-name: "with_wrong_reg_type_j" 631 description: > 632 Check that verifier reports error when the register contains 633 a value of type not corresponding to the bytecode in PandaAssembly context. 634 isa: 635 verification: 636 - v1_type 637 header-template: ['PandaAssembly_header'] 638 check-type: exit-positive 639 tags: [verifier, pa-verifier] 640 runner-options: ['use-pa', 'verifier-failure', 'verifier-config'] 641 code-template: | 642 .function i32 main() { 643 newobj v0, R 644 %s 645 stobj.v.64 v1, v0, %s 646 cases: 647 # i64 648 - values: 649 - movi v1, 0 650 - R.fi64 651 - values: 652 - movi v1, 0xCAFECAFE 653 - R.fi64 654 - values: 655 - fmovi v1, 1.1 656 - R.fi64 657 - values: 658 - fmovi.64 v1, 1.1 659 - R.fi64 660 - values: 661 - mov.null v1 662 - R.fi64 663 - values: 664 - newobj v1, Q 665 - R.fi64 666 - values: 667 - | 668 # 669 movi v1, 10 670 newarr v1, v1, panda.Object[] 671 - R.fi64 672 # f64 673 - values: 674 - movi v1, 0 675 - R.ff64 676 - values: 677 - movi v1, 0xCAFECAFE 678 - R.ff64 679 - values: 680 - movi.64 v1, 1 681 - R.ff64 682 - values: 683 - fmovi v1, 1.1 684 - R.ff64 685 bugid: ['6094'] 686 - values: 687 - mov.null v1 688 - R.ff64 689 - values: 690 - newobj v1, Q 691 - R.ff64 692 - values: 693 - | 694 # 695 movi v1, 10 696 newarr v1, v1, panda.Object[] 697 - R.ff64 698 699 700 - file-name: "op_v1_4_v2_4_id_16" 701 description: Check that compiler reports error when the register number is out of 4 bit size 702 isa: 703 instructions: 704 - sig: stobj.v.64 v1:in:b64, v2:in:ref, field_id 705 acc: none 706 format: [op_v1_4_v2_4_id_16] 707 header-template: ['pandasm_header'] 708 runner-options: ['compile-failure'] 709 check-type: exit-positive 710 code-template: | 711 712 .function i32 main() { 713 stobj.v.64 %s, R.ff64 714 cases: 715 - values: ['v15, v15'] 716 runner-options: ['compile-only'] 717 - values: ['v16, v15'] 718 - values: ['v15, v16'] 719 - values: ['v255, v0'] 720 - values: ['v15, v256'] 721 - values: ['v65535, v65535'] 722 - values: ['v32767, v0'] 723 724 725 - file-name: "into_all_field_types" 726 description: Check that register value is stored in field. 727 isa: 728 instructions: 729 - sig: stobj.v.64 v1:in:b64, v2:in:ref, field_id 730 acc: none 731 format: [op_v1_4_v2_4_id_16] 732 header-template: ['pandasm_header'] 733 check-type: exit-positive 734 tags: ['tsan', 'irtoc_ignore'] 735 code-template: | 736 .function i32 main() { 737 movi v7, 5151515 738 newobj v0, R 739 %s 740 ldai 5151515 741 stobj.v.64 v1, v0, R.%s 742 jeq v7, cont # check acc_none 743 ldai 2 744 return 745 cont: 746 ldobj.v.64 v2, v0, R.%s 747 lda.64 v2 748 %s 749 jeqz success 750 ldai 1 751 return 752 success: 753 cases: 754 # u64 755 - values: 756 - movi.64 v1, 0x0000000000000000 757 - fu64 758 - fu64 759 - | 760 # 761 movi.64 v1, 0x0000000000000000 762 ucmp.64 v1 763 - values: 764 - movi.64 v1, 0xffffffffffffffff 765 - fu64 766 - fu64 767 - | 768 # 769 movi.64 v1, 0xffffffffffffffff 770 ucmp.64 v1 771 - values: 772 - movi.64 v1, 0xa5a5a5a5a5a5a5a5 773 - fu64 774 - fu64 775 - | 776 # 777 movi.64 v1, 0xa5a5a5a5a5a5a5a5 778 ucmp.64 v1 779 # i64 780 - values: 781 - movi.64 v1, 0 782 - fi64 783 - fi64 784 - | 785 # 786 movi.64 v1, 0 787 cmp.64 v1 788 - values: 789 - movi.64 v1, -1 790 - fi64 791 - fi64 792 - | 793 # 794 movi.64 v1, -1 795 cmp.64 v1 796 - values: 797 - movi.64 v1, -6510615555426900571 798 - fi64 799 - fi64 800 - | 801 # 802 movi.64 v1, -6510615555426900571 803 cmp.64 v1 804 # f64 805 - values: 806 - fmovi.64 v1, 0.0 807 - ff64 808 - ff64 809 - | 810 # 811 fmovi.64 v1, 0.0 812 fcmpg.64 v1 813 - values: 814 - fmovi.64 v1, -6510615555426900571.0 815 - ff64 816 - ff64 817 - | 818 # 819 fmovi.64 v1, -6510615555426900571.0 820 fcmpg.64 v1 821 - values: 822 - fmovi.64 v1, 0x7FFFFFFFFFFFFFFF # NaN 823 - ff64 824 - ff64 825 - | 826 # 827 fmovi.64 v1, 0.0 828 fcmpg.64 v1 829 subi 1 830 - values: 831 - fmovi.64 v1, 0x7ff0000000000000 # + Inf 832 - ff64 833 - ff64 834 - | 835 # 836 fmovi.64 v1, 0x7ff0000000000000 837 fcmpg.64 v1 838 - values: 839 - fmovi.64 v1, 0xfff0000000000000 # - Inf 840 - ff64 841 - ff64 842 - | 843 # 844 fmovi.64 v1, 0xfff0000000000000 845 fcmpg.64 v1 846