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