• 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: java_header
16    template: |
17      .language Java
18
19      .record java.lang.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        java.lang.Object   fObj
40        java.lang.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-debug-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.ff32'
120
121
122      - file-name: "check_if_v2_initialized_j"
123        description: Check that verifier reports error if source registers are not initialized in Java 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: ['java_header']
130        check-type: exit-positive
131        tags: ['verifier']
132        bugid: ['1324', '2084', '3257', '3293']
133        runner-options: ['verifier-failure', 'verifier-debug-config', 'use-java']
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.fi32'
141          - values:
142            - 'ldobj.v.64 v15, v1, R.fi64'
143          - values:
144            - 'ldobj.v.64 v15, v15, R.ff32'
145
146
147      - file-name: "with_null_ref_p"
148        description: Check that NullPointerException is thrown if object ref is null in Panda context.
149        isa:
150          exceptions:
151            - x_null
152        header-template: ['pandasm_header', 'get_null_R']
153        check-type: empty
154        tags: ['tsan']
155        code-template: |
156          .record panda.NullPointerException <external>
157
158          .function i32 main() {
159            call.short get_null_R
160            sta.obj v0
161          try_begin:
162            ldobj.v.64 v1, v0, %s
163            ldai 1
164            return
165          try_end:
166            ldai 0
167            return
168          .catch panda.NullPointerException, try_begin, try_end, try_end
169          }
170        cases:
171          - values:
172            - R.fi64
173          - values:
174            - R.fu64
175          - values:
176            - R.ff64
177          - values:
178            - R.ff32
179
180
181      - file-name: "with_non_object_ref_p"
182        description: Check that verifier reports an error when the 2nd operand is not a ref to an object (other than array) in Panda context.
183        isa:
184          verification:
185            - v2_object
186        header-template: ['pandasm_header']
187        check-type: exit-positive
188        tags: ['verifier']
189        bugid: ['2085']
190        runner-options: ['verifier-failure', 'verifier-debug-config']
191        code-template: |
192          .function i32 main() {
193            %s
194            ldobj.v.64 v1, v0, R.fi64
195        cases:
196          - values:
197            - movi v0, 0
198            tags: ['release', 'clang_release_sanitizer']
199            bugid: ['1324', '1826']
200          - values:
201            - movi v0, 1
202          - values:
203            - movi.64 v0, 0x00
204            tags: ['release', 'clang_release_sanitizer']
205            bugid: ['1324', '1826']
206          - values:
207            - movi.64 v0, 0xCAFECAFECAFECAFE
208          - values:
209            - fmovi.64 v0, 0.0
210            tags: ['release', 'clang_release_sanitizer']
211            bugid: ['1324', '1826']
212          - values:
213            - fmovi.64 v0, 6.62607015
214          - values:
215            - |
216              #
217                movi v1, 10
218                newarr v0, v1, R[]
219            bugid: ['1827']
220
221
222      - file-name: "with_non_object_ref_j"
223        description: Check that verifier reports an error when the 2nd operand is not a ref to an object (other than array) in Java context.
224        isa:
225          verification:
226            - v2_object
227        header-template: ['java_header']
228        check-type: exit-positive
229        tags: ['verifier']
230        bugid: ['3293']
231        runner-options: ['verifier-failure', 'verifier-debug-config', 'use-java']
232        code-template: |
233          .function i32 main() {
234            %s
235            ldobj.v.64 v15, v0, R.fi64
236        cases:
237          - values:
238            - movi v0, 0
239          - values:
240            - movi v0, 1
241          - values:
242            - movi.64 v0, 0x00
243          - values:
244            - movi.64 v0, 0xCAFECAFECAFECAFE
245          - values:
246            - fmovi.64 v0, 0.0
247          - values:
248            - fmovi.64 v0, 6.62607015
249          - values:
250            - |
251              #
252                movi v1, 10
253                newarr v0, v1, R[]
254
255
256      - file-name: "with_static_field_id_p"
257        description: |
258          Check that verifier reports an error when the field doesn't resolve to a non-static valid object field in Panda context.
259          Incorrect usage cannot be compiled.
260        isa:
261          verification:
262            - field_id_non_static
263        header-template: []
264        runner-options: ['compile-failure']
265        bugid: ['1324', '1828', '1833', '2086']
266        check-type: exit-positive
267        code-template: |
268          .record W {
269            i64   static_field  <static>
270          }
271          .function void W.ctor(W a0) <ctor> {
272            return.void
273          }
274          .record random_record_name {
275            i64 random_field_name
276          }
277          .function void random_function_name() {
278            return.void
279          }
280
281          .function i32 main() {
282            initobj W.ctor
283            sta.obj v0
284            ldobj.v.64 v1, v0, %s
285        cases:
286          - values:
287            - W.static_field
288            runner-options: ['verifier-failure', 'verifier-debug-config']
289            tags: ['verifier']
290          - values:
291            - random_record_name
292          - values:
293            - random_function_name
294          - values:
295            - W.field_not_exists
296          - values:
297            - random_record_name.random_field_name
298            runner-options: ['verifier-failure', 'verifier-debug-config']
299            tags: ['verifier']
300            bugid: ['3536']
301          - values:
302            - 0
303          - values:
304            - -1.1
305          - values:
306            - "null"
307          - values:
308            - "\"abc\""
309
310
311      - file-name: "with_static_field_id_j"
312        description: |
313          Check that verifier reports an error when the field doesn't resolve to a non-static valid object field in Java context.
314          Incorrect usage cannot be compiled.
315        isa:
316          verification:
317            - field_id_non_static
318        header-template: []
319        runner-options: ['compile-failure', 'use-java']
320        tags: ['verifier']
321        bugid: ['1324', '1828', '1833', '2086', '3293']
322        check-type: exit-positive
323        code-template: |
324          .language Java
325          .record W {
326            i64   static_field  <static>
327          }
328          .function void W.ctor(W a0) <ctor> {
329            return.void
330          }
331          .record random_record_name {
332            i64 random_field_name
333          }
334          .function void random_function_name() {
335            return.void
336          }
337
338          .function i32 main() {
339            initobj W.ctor
340            sta.obj v0
341            ldobj.v.64 v15, v0, %s
342        cases:
343          - values:
344            - W.static_field
345            tags: ['verifier']
346            runner-options: ['verifier-failure', 'verifier-debug-config', 'use-java']
347          - values:
348            - random_record_name
349          - values:
350            - random_function_name
351          - values:
352            - W.field_not_exists
353          - values:
354            - random_record_name.random_field_name
355            tags: ['verifier']
356            runner-options: ['verifier-failure', 'verifier-debug-config', 'use-java']
357            bugid: ['3536']
358          - values:
359            - 0
360          - values:
361            - -1.1
362          - values:
363            - "null"
364          - values:
365            - "\"abc\""
366
367
368      - file-name: "with_wrong_field_size_or_type_p"
369        description: Check that verifier reports an error when the field resolves to a field with size or type that is not corresponding to bytecode
370        isa:
371          verification:
372            - field_id_size
373        header-template: ['pandasm_header']
374        check-type: exit-positive
375        tags: ['verifier']
376        runner-options: ['verifier-failure', 'verifier-debug-config']
377        bugid: ['1834', '2088']
378        code-template: |
379
380          .function i32 main() {
381            initobj R.ctor
382            sta.obj v0
383            ldobj.v.64 v1, v0, %s
384        cases:
385          - values:
386            - R.fu1
387          - values:
388            - R.fu8
389          - values:
390            - R.fi8
391          - values:
392            - R.fu16
393          - values:
394            - R.fi16
395          - values:
396            - R.fu32
397          - values:
398            - R.fi32
399          - values:
400            - R.fObj
401          - values:
402            - R.fObjArray
403          - values:
404            - R.fi32Array
405
406
407      - file-name: "with_wrong_field_size_or_type_j"
408        description: Check that verifier reports an error when the field resolves to a field with size or type that is not corresponding to bytecode
409        isa:
410          verification:
411            - field_id_size
412        header-template: ['java_header']
413        check-type: exit-positive
414        tags: ['verifier']
415        bugid: ['1834', '2088', '3293']
416        runner-options: ['verifier-failure', 'verifier-debug-config', 'use-java']
417        code-template: |
418
419          .function i32 main() {
420            initobj R.ctor
421            sta.obj v0
422            ldobj.v.64 v15, v0, %s
423        cases:
424          - values:
425            - R.fu1
426          - values:
427            - R.fi8
428          - values:
429            - R.fi16
430          - values:
431            - R.fu16
432          - values:
433            - R.fi32
434          - values:
435            - R.fObj
436          - values:
437            - R.fObjArray
438          - values:
439            - R.fi32Array
440
441
442      - file-name: "op_v1_4_v2_4_id_16"
443        description: Check that compiler reports an error when the register number is incorrect
444        isa:
445          instructions:
446            - sig: ldobj.v.64 v1:out:b64, v2:in:ref, field_id
447              acc: none
448              format: [op_v1_4_v2_4_id_16]
449        header-template: ['pandasm_header']
450        check-type: exit-positive
451        runner-options: ['compile-failure']
452        code-template: |
453
454          .function i32 main() {
455            ldobj.v.64 %s, R.fi64
456        cases:
457          - values: ['v15, v15']
458            runner-options: ['compile-only']
459          - values: ['v0, v16']
460          - values: ['v16, v0']
461          - values: ['v256, v0']
462          - values: ['v1, v256']
463          - values: ['v32567, v32567']
464          - values: ['a0, v1']
465          - values: ['v0, a1']
466          - values: ['v0']
467          - values: ['1']
468          - values: ['"0"']
469
470
471      - file-name: "from_all_int_field_types"
472        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
473        isa:
474          instructions:
475            - sig: ldobj.v.64 v1:out:b64, v2:in:ref, field_id
476              acc: none
477              format: [op_v1_4_v2_4_id_16]
478        header-template: ['pandasm_header']
479        check-type: exit-positive
480        tags: ['tsan']
481        code-template: |
482
483          .function i32 main() {
484            initobj.short R.ctor
485            sta.obj v0
486            ldai.64 %s
487            stobj.64 v0, R.f%s
488            movi.64 v15, %s
489            ldobj.v.64 v1, v0, R.f%s
490            lda.64 v1
491            %s v15
492            jeqz success
493            ldai 1
494            return
495          success:
496        cases:
497          # u64
498          - values: [0, 'u64', 0, 'u64', 'ucmp.64']
499          - values: [0xffffffffffffffff, 'u64', 0xffffffffffffffff, 'u64', 'ucmp.64']
500          - values: [0xa5a5a5a5a5a5a5a5, 'u64', 0xa5a5a5a5a5a5a5a5, 'u64', 'ucmp.64']
501          # i64
502          - values: [0, 'i64', 0, 'i64', 'cmp.64']
503          - values: [-1, 'i64', -1, 'i64', 'cmp.64']
504          - values: [-6510615555426900571, 'i64', -6510615555426900571, 'i64', 'cmp.64']
505
506      - file-name: "from_float_field_type"
507        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
508        isa:
509          instructions:
510            - sig: ldobj.v.64 v1:out:b64, v2:in:ref, field_id
511              acc: none
512              format: [op_v1_4_v2_4_id_16]
513        header-template: ['pandasm_header']
514        bugid: ['3292']
515        check-type: exit-positive
516        code-template: |
517
518          .function i32 main() {
519            initobj.short R.ctor
520            sta.obj v0
521            %s
522            stobj.64 v0, R.ff64
523            lda.null
524            %s
525            ldobj.v.64 v1, v0, R.ff64
526            lda.64 v1
527            fcmpg.64 v15
528            %s
529            jeqz success
530            ldai 1
531            return
532          success:
533        cases:
534          # f64
535          - values: ['fldai.64 0.0', 'fmovi.64 v15, 0.0', '']
536          - values: ['fldai.64 -6510615555426900571.0', 'fmovi.64 v15, -6510615555426900571.0', '']
537          - values: ['fldai.64 0x7FFFFFFFFFFFFFFF', 'fmovi.64 v15, 0x7FFFFFFFFFFFFFFF', 'subi 1']    # NaN
538          - values: ['fldai.64 0x7ff0000000000000', 'fmovi.64 v15, 0x7ff0000000000000', '']    # + Inf
539          - values: ['fldai.64 0xfff0000000000000', 'fmovi.64 v15, 0xfff0000000000000', '']    # - Inf
540