• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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: PandaAssembly_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        i8             fi8
29        i16            fi16
30        u16            fu16
31        i32            fi32
32        i64            fi64
33        f32            ff32
34        f64            ff64
35
36        i32[]          fi32Array
37        Q              fQ
38        Q[]            fQArray
39        panda.Object   fObj
40        panda.Object[] fObjArray
41      }
42      .function void R.ctor(R a0) <ctor> {
43        return.void
44      }
45  - name: pandasm_header
46    template: |
47      .language PandaAssembly
48
49      .record panda.Object <external>
50
51      .record Q {}
52      .function void Q.ctor(Q a0) <ctor> {
53        return.void
54      }
55
56      .record R {
57        u1             fu1
58        u8             fu8
59        i8             fi8
60        u16            fu16
61        i16            fi16
62        u32            fu32
63        i32            fi32
64        u64            fu64
65        i64            fi64
66        f32            ff32
67        f64            ff64
68
69        i32[]          fi32Array
70        Q              fQ
71        Q[]            fQArray
72        panda.Object   fObj
73        panda.Object[] fObjArray
74      }
75      .function void R.ctor(R a0) <ctor> {
76        return.void
77      }
78  - name: get_null_R
79    template: |
80      .function R get_null_R() {
81          lda.null
82          return.obj
83      }
84
85tests:
86  - file-name: "ldobj.v.64"
87    isa:
88      title: Get field from object to register
89      description: >
90        Get field value from an object by field id and put it into register.
91      instructions:
92        - sig: ldobj.v.64 v1:out:b64, v2:in:ref, field_id
93          acc: none
94          format: [op_v1_4_v2_4_id_16]
95    commands:
96
97      - file-name: "check_if_v2_initialized_p"
98        description: Check that verifier reports error if source registers are not initialized in Panda context.
99        isa:
100          instructions:
101            - sig: ldobj.v.64 v1:out:b64, v2:in:ref, field_id
102              acc: none
103              format: [op_v1_4_v2_4_id_16]
104        header-template: ['pandasm_header']
105        check-type: exit-positive
106        tags: ['verifier']
107        bugid: ['1324', '2084', '3257']
108        runner-options: ['verifier-failure', 'verifier-config']
109        code-template: |
110
111          .function i32 main() {
112            %s  # verifier error expected, because v2 is not initialized
113        cases:
114          - values:
115            - 'ldobj.v.64 v0, v0, R.fu64'
116          - values:
117            - 'ldobj.v.64 v0, v1, R.fi64'
118          - values:
119            - 'ldobj.v.64 v0, v15, R.ff64'
120
121
122      - file-name: "check_if_v2_initialized_j"
123        description: Check that verifier reports error if source registers are not initialized in PandaAssembly context.
124        isa:
125          instructions:
126            - sig: ldobj.v.64 v1:out:b64, v2:in:ref, field_id
127              acc: none
128              format: [op_v1_4_v2_4_id_16]
129        header-template: ['PandaAssembly_header']
130        check-type: exit-positive
131        tags: [verifier, pa-verifier]
132        bugid: ['1324', '2084', '3257', '3293']
133        runner-options: ['verifier-failure', 'verifier-config', 'use-pa']
134        code-template: |
135
136          .function i32 main() {
137            %s  # verifier error expected, because v2 is not initialized
138        cases:
139          - values:
140            - 'ldobj.v.64 v15, v0, R.fi64'
141          - values:
142            - 'ldobj.v.64 v15, v15, R.ff64'
143
144
145      - file-name: "with_null_ref_p"
146        description: Check that NullPointerException is thrown if object ref is null in Panda context.
147        isa:
148          exceptions:
149            - x_null
150        header-template: ['pandasm_header', 'get_null_R']
151        check-type: empty
152        tags: ['tsan', 'irtoc_ignore']
153        code-template: |
154          .record panda.NullPointerException <external>
155
156          .function i32 main() {
157            call.short get_null_R
158            sta.obj v0
159          try_begin:
160            ldobj.v.64 v1, v0, %s
161            ldai 1
162            return
163          try_end:
164            ldai 0
165            return
166          .catch panda.NullPointerException, try_begin, try_end, try_end
167          }
168        cases:
169          - values:
170            - R.fi64
171          - values:
172            - R.fu64
173          - values:
174            - R.ff64
175
176
177      - file-name: "with_null_ref_j"
178        description: Check that NullPointerException is thrown if object ref is null in PandaAssembly context.
179        isa:
180          exceptions:
181            - x_null
182        runner-options: [use-pa]
183        header-template: ['PandaAssembly_header', 'get_null_R']
184        check-type: empty
185        tags: ['tsan', 'irtoc_ignore']
186        code-template: |
187          .record panda.NullPointerException <external>
188
189          .function i32 main() {
190            call.short get_null_R
191            sta.obj v0
192          try_begin:
193            ldobj.v.64 v15, v0, %s
194            ldai 1
195            return
196          try_end:
197            ldai 0
198            return
199          .catch panda.NullPointerException, try_begin, try_end, try_end
200          }
201        cases:
202          - values:
203            - R.fi64
204          - values:
205            - R.ff64
206
207
208      - file-name: "with_non_object_ref_p"
209        description: Check that verifier reports an error when the 2nd operand is not a ref to an object (other than array) in Panda context.
210        isa:
211          verification:
212            - v2_object
213        header-template: ['pandasm_header']
214        check-type: exit-positive
215        tags: ['verifier']
216        bugid: ['2085']
217        runner-options: ['verifier-failure', 'verifier-config']
218        code-template: |
219          .function i32 main() {
220            %s
221            ldobj.v.64 v1, v0, R.fi64
222        cases:
223          - values:
224            - movi v0, 0
225            bugid: ['1324', '1826']
226          - values:
227            - movi v0, 1
228          - values:
229            - movi.64 v0, 0x00
230            bugid: ['1324', '1826']
231          - values:
232            - movi.64 v0, 0xCAFECAFECAFECAFE
233          - values:
234            - fmovi.64 v0, 0.0
235            bugid: ['1324', '1826']
236          - values:
237            - fmovi.64 v0, 6.62607015
238          - values:
239            - |
240              #
241                movi v1, 10
242                newarr v0, v1, R[]
243            bugid: ['1827']
244
245
246      - file-name: "with_non_object_ref_j"
247        description: Check that verifier reports an error when the 2nd operand is not a ref to an object (other than array) in PandaAssembly context.
248        isa:
249          verification:
250            - v2_object
251        header-template: ['PandaAssembly_header']
252        check-type: exit-positive
253        tags: [verifier, pa-verifier]
254        bugid: ['3293']
255        runner-options: ['verifier-failure', 'verifier-config', 'use-pa']
256        code-template: |
257          .function i32 main() {
258            %s
259            ldobj.v.64 v15, v0, R.fi64
260        cases:
261          - values:
262            - movi v0, 0
263          - values:
264            - movi v0, 1
265          - values:
266            - movi.64 v0, 0x00
267          - values:
268            - movi.64 v0, 0xCAFECAFECAFECAFE
269          - values:
270            - fmovi.64 v0, 0.0
271          - values:
272            - fmovi.64 v0, 6.62607015
273          - values:
274            - |
275              #
276                movi v1, 10
277                newarr v0, v1, R[]
278
279
280      - file-name: "with_static_field_id_p"
281        description: |
282          Check that verifier reports an error when the field doesn't resolve to a non-static valid object field in Panda context.
283          Incorrect usage cannot be compiled.
284        isa:
285          verification:
286            - field_id_non_static
287        header-template: []
288        runner-options: ['compile-failure']
289        bugid: ['1324', '1828', '1833', '2086']
290        check-type: exit-positive
291        code-template: |
292          .record W {
293            i64   static_field  <static>
294          }
295          .function void W.ctor(W a0) <ctor> {
296            return.void
297          }
298          .record random_record_name {
299            i64 random_field_name
300          }
301          .function void random_function_name() {
302            return.void
303          }
304
305          .function i32 main() {
306            initobj W.ctor
307            sta.obj v0
308            ldobj.v.64 v1, v0, %s
309        cases:
310          - values:
311            - W.static_field
312            runner-options: ['verifier-failure', 'verifier-config']
313            tags: ['verifier']
314          - values:
315            - random_record_name
316          - values:
317            - random_function_name
318          - values:
319            - W.field_not_exists
320          - values:
321            - random_record_name.random_field_name
322            runner-options: ['verifier-failure', 'verifier-config']
323            tags: ['verifier']
324            bugid: ['3536']
325          - values:
326            - 0
327          - values:
328            - -1.1
329          - values:
330            - "null"
331          - values:
332            - "\"abc\""
333
334
335      - file-name: "with_static_field_id_j"
336        description: |
337          Check that verifier reports an error when the field doesn't resolve to a non-static valid object field in PandaAssembly context.
338          Incorrect usage cannot be compiled.
339        isa:
340          verification:
341            - field_id_non_static
342        header-template: []
343        runner-options: ['compile-failure', 'use-pa']
344        tags: [verifier, pa-verifier]
345        bugid: ['1324', '1828', '1833', '2086', '3293']
346        check-type: exit-positive
347        code-template: |
348          .language PandaAssembly
349          .record W {
350            i64   static_field  <static>
351          }
352          .function void W.ctor(W a0) <ctor> {
353            return.void
354          }
355          .record random_record_name {
356            i64 random_field_name
357          }
358          .function void random_function_name() {
359            return.void
360          }
361
362          .function i32 main() {
363            initobj W.ctor
364            sta.obj v0
365            ldobj.v.64 v15, v0, %s
366        cases:
367          - values:
368            - W.static_field
369            tags: [verifier, pa-verifier]
370            runner-options: ['verifier-failure', 'verifier-config', 'use-pa']
371          - values:
372            - random_record_name
373          - values:
374            - random_function_name
375          - values:
376            - W.field_not_exists
377          - values:
378            - random_record_name.random_field_name
379            tags: [verifier, pa-verifier]
380            runner-options: ['verifier-failure', 'verifier-config', 'use-pa']
381            bugid: ['3536']
382          - values:
383            - 0
384          - values:
385            - -1.1
386          - values:
387            - "null"
388          - values:
389            - "\"abc\""
390
391
392      - file-name: "with_wrong_field_size_or_type_p"
393        description: Check that verifier reports an error when the field resolves to a field with size or type that is not corresponding to bytecode
394        isa:
395          verification:
396            - field_id_size
397        header-template: ['pandasm_header']
398        check-type: exit-positive
399        tags: ['verifier']
400        runner-options: ['verifier-failure', 'verifier-config']
401        bugid: ['1834', '2088']
402        code-template: |
403
404          .function i32 main() {
405            initobj R.ctor
406            sta.obj v0
407            ldobj.v.64 v1, v0, %s
408        cases:
409          - values:
410            - R.fu1
411          - values:
412            - R.fu8
413          - values:
414            - R.fi8
415          - values:
416            - R.fu16
417          - values:
418            - R.fi16
419          - values:
420            - R.fu32
421          - values:
422            - R.fi32
423          - values:
424            - R.ff32
425            bugid: ['6094']
426          - values:
427            - R.fObj
428          - values:
429            - R.fObjArray
430          - values:
431            - R.fi32Array
432
433
434      - file-name: "with_wrong_field_size_or_type_j"
435        description: Check that verifier reports an error when the field resolves to a field with size or type that is not corresponding to bytecode
436        isa:
437          verification:
438            - field_id_size
439        header-template: ['PandaAssembly_header']
440        check-type: exit-positive
441        tags: [verifier, pa-verifier]
442        bugid: ['1834', '2088', '3293']
443        runner-options: ['verifier-failure', 'verifier-config', 'use-pa']
444        code-template: |
445
446          .function i32 main() {
447            initobj R.ctor
448            sta.obj v0
449            ldobj.v.64 v15, v0, %s
450        cases:
451          - values:
452            - R.fu1
453          - values:
454            - R.fi8
455          - values:
456            - R.fi16
457          - values:
458            - R.fu16
459          - values:
460            - R.fi32
461          - values:
462            - R.ff32
463            bugid: ['6094']
464          - values:
465            - R.fObj
466          - values:
467            - R.fObjArray
468          - values:
469            - R.fi32Array
470
471
472      - file-name: "with_correct_field_size_or_type_p"
473        description: Check that verifier does not report any error when the field has size or type that is corresponding to bytecode
474        isa:
475          verification:
476            - field_id_size
477        header-template: ['pandasm_header']
478        check-type: exit-positive
479        tags: ['verifier']
480        runner-options: ['verifier-only', 'verifier-config']
481        code-template: |
482
483          .function i32 main() {
484            initobj R.ctor
485            sta.obj v0
486            ldobj.v.64 v15, v0, %s
487        cases:
488          - values:
489            - R.fu64
490          - values:
491            - R.fi64
492          - values:
493            - R.ff64
494
495
496      - file-name: "op_v1_4_v2_4_id_16"
497        description: Check that compiler reports an error when the register number is incorrect
498        isa:
499          instructions:
500            - sig: ldobj.v.64 v1:out:b64, v2:in:ref, field_id
501              acc: none
502              format: [op_v1_4_v2_4_id_16]
503        header-template: ['pandasm_header']
504        check-type: exit-positive
505        runner-options: ['compile-failure']
506        code-template: |
507
508          .function i32 main() {
509            ldobj.v.64 %s, R.fi64
510        cases:
511          - values: ['v15, v15']
512            runner-options: ['compile-only']
513          - values: ['v0, v16']
514          - values: ['v16, v0']
515          - values: ['v256, v0']
516          - values: ['v1, v256']
517          - values: ['v32567, v32567']
518          - values: ['a0, v1']
519          - values: ['v0, a1']
520          - values: ['v0']
521          - values: ['1']
522          - values: ['"0"']
523
524
525      - file-name: "from_all_int_field_types"
526        description: Check that accumulator value is loaded from field into accumulator. More tests on ldobj.v.64 can be found in stobj.v.64 tests
527        isa:
528          instructions:
529            - sig: ldobj.v.64 v1:out:b64, v2:in:ref, field_id
530              acc: none
531              format: [op_v1_4_v2_4_id_16]
532        header-template: ['pandasm_header']
533        check-type: exit-positive
534        tags: ['tsan']
535        code-template: |
536
537          .function i32 main() {
538            initobj.short R.ctor
539            sta.obj v0
540            ldai.64 %s
541            stobj.64 v0, R.f%s
542            movi.64 v15, %s
543            ldobj.v.64 v1, v0, R.f%s
544            lda.64 v1
545            %s v15
546            jeqz success
547            ldai 1
548            return
549          success:
550        cases:
551          # u64
552          - values: [0, 'u64', 0, 'u64', 'ucmp.64']
553          - values: [0xffffffffffffffff, 'u64', 0xffffffffffffffff, 'u64', 'ucmp.64']
554          - values: [0xa5a5a5a5a5a5a5a5, 'u64', 0xa5a5a5a5a5a5a5a5, 'u64', 'ucmp.64']
555          # i64
556          - values: [0, 'i64', 0, 'i64', 'cmp.64']
557          - values: [-1, 'i64', -1, 'i64', 'cmp.64']
558          - values: [-6510615555426900571, 'i64', -6510615555426900571, 'i64', 'cmp.64']
559
560
561      - file-name: "from_float_field_type"
562        description: Check that accumulator value is loaded from field into accumulator. More tests on ldobj.v.64 can be found in stobj.v.64 tests
563        isa:
564          instructions:
565            - sig: ldobj.v.64 v1:out:b64, v2:in:ref, field_id
566              acc: none
567              format: [op_v1_4_v2_4_id_16]
568        header-template: ['pandasm_header']
569        tags: ['irtoc_ignore']
570        bugid: ['3292']
571        check-type: exit-positive
572        code-template: |
573
574          .function i32 main() {
575            initobj.short R.ctor
576            sta.obj v0
577            %s
578            stobj.64 v0, R.ff64
579            lda.null
580            %s
581            ldobj.v.64 v1, v0, R.ff64
582            lda.64 v1
583            fcmpg.64 v15
584            %s
585            jeqz success
586            ldai 1
587            return
588          success:
589        cases:
590          # f64
591          - values: ['fldai.64 0.0', 'fmovi.64 v15, 0.0', '']
592          - values: ['fldai.64 -6510615555426900571.0', 'fmovi.64 v15, -6510615555426900571.0', '']
593          - values: ['fldai.64 0x7FFFFFFFFFFFFFFF', 'fmovi.64 v15, 0x7FFFFFFFFFFFFFFF', 'subi 1']    # NaN
594          - values: ['fldai.64 0x7ff0000000000000', 'fmovi.64 v15, 0x7ff0000000000000', '']    # + Inf
595          - values: ['fldai.64 0xfff0000000000000', 'fmovi.64 v15, 0xfff0000000000000', '']    # - Inf
596