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