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