• 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.64"
87    isa:
88      title: Get field from object to accumulator
89      description: >
90        Get field value from an object by field id and put it into accumulator.
91      instructions:
92        - sig: ldobj.64 v:in:ref, field_id
93          acc: out:b64
94          format: [op_v_8_id_16]
95    commands:
96
97      - file-name: "check_if_regs_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.64 v:in:ref, field_id
102              acc: out:b64
103              format: [op_v_8_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 the register is not initialized
113        cases:
114          - values:
115            - 'ldobj.64 v0, R.fu64'
116          - values:
117            - 'ldobj.64 v1, R.fi64'
118          - values:
119            - 'ldobj.64 v15, R.ff32'
120          - values:
121            - 'ldobj.64 v240, R.ff64'
122          - values:
123            - 'ldobj.64 v255, R.fu64'
124
125      - file-name: "with_null_ref_p"
126        description: Check that NullPointerException is thrown if object ref is null in Panda context.
127        isa:
128          exceptions:
129            - x_null
130        header-template: ['pandasm_header', 'get_null_R']
131        check-type: empty
132        tags: ['tsan']
133        code-template: |
134          .record panda.NullPointerException <external>
135
136          .function i32 main() {
137            call.short get_null_R
138            sta.obj v0
139          try_begin:
140            ldobj.64 v0, %s
141            ldai 1
142            return
143          try_end:
144            ldai 0
145            return
146          .catch panda.NullPointerException, try_begin, try_end, try_end
147          }
148        cases:
149          - values:
150            - R.fi64
151          - values:
152            - R.fu64
153          - values:
154            - R.ff64
155          - values:
156            - R.ff32
157
158      - file-name: "with_non_object_ref_p"
159        description: Check that verifier reports an error when the 1st operand is not a ref to an object (other than array) in Panda context.
160        isa:
161          verification:
162            - v1_object
163        header-template: ['pandasm_header']
164        check-type: exit-positive
165        tags: ['verifier']
166        bugid: ['2085']
167        runner-options: ['verifier-failure', 'verifier-debug-config']
168        code-template: |
169          .function i32 main() {
170            %s
171            ldobj.64 v0, R.fi64
172        cases:
173          - values:
174            - movi v0, 0
175            tags: ['release', 'clang_release_sanitizer']
176            bugid: ['1324', '1826']
177          - values:
178            - movi v0, 1
179          - values:
180            - movi.64 v0, 0x00
181            tags: ['release', 'clang_release_sanitizer']
182            bugid: ['1324', '1826']
183          - values:
184            - movi.64 v0, 0xCAFECAFECAFECAFE
185          - values:
186            - fmovi.64 v0, 0.0
187            tags: ['release', 'clang_release_sanitizer']
188            bugid: ['1324', '1826']
189          - values:
190            - fmovi.64 v0, 6.62607015
191          - values:
192            - |
193                movi v1, 10
194                  newarr v0, v1, R[]
195            bugid: ['1827']
196
197      - file-name: "with_static_field_id_p"
198        description: |
199          Check that verifier reports an error when the field doesn't resolve to a non-static valid object field in Panda context.
200          Incorrect usage cannot be compiled.
201        isa:
202          verification:
203            - field_id_non_static
204        header-template: []
205        runner-options: ['compile-failure']
206        bugid: ['1324', '1828', '1833', '2086']
207        check-type: exit-positive
208        code-template: |
209          .record W {
210            i64   static_field  <static>
211          }
212          .function void W.ctor(W a0) <ctor> {
213            return.void
214          }
215          .record random_record_name {
216            i64 random_field_name
217          }
218          .function void random_function_name() {
219            return.void
220          }
221
222          .function i32 main() {
223            initobj W.ctor
224            sta.obj v0
225            ldobj.64 v0, %s
226        cases:
227          - values:
228            - W.static_field
229            runner-options: ['verifier-failure', 'verifier-debug-config']
230            tags: ['verifier']
231          - values:
232            - random_record_name
233          - values:
234            - random_function_name
235          - values:
236            - W.field_not_exists
237          - values:
238            - random_record_name.random_field_name
239            runner-options: ['verifier-failure', 'verifier-debug-config']
240            tags: ['verifier']
241            bugid: ['3536']
242            ignore: true
243          - values:
244            - 0
245          - values:
246            - -1.1
247          - values:
248            - "null"
249          - values:
250            - "\"abc\""
251
252      - file-name: "with_wrong_field_size_or_type_p"
253        description: Check that verifier reports an error when the field resolves to a field with size or type that is not corresponding to bytecode
254        isa:
255          verification:
256            - field_id_size
257        header-template: ['pandasm_header']
258        check-type: exit-positive
259        tags: ['verifier']
260        runner-options: ['verifier-failure', 'verifier-debug-config']
261        bugid: ['1834', '2088']
262        code-template: |
263
264          .function i32 main() {
265            initobj R.ctor
266            sta.obj v0
267            ldobj.64 v0, %s
268        cases:
269          - values:
270            - R.fu1
271          - values:
272            - R.fu8
273          - values:
274            - R.fi8
275          - values:
276            - R.fu16
277          - values:
278            - R.fi16
279          - values:
280            - R.fu32
281          - values:
282            - R.fi32
283          - values:
284            - R.fObj
285          - values:
286            - R.fObjArray
287          - values:
288            - R.fi32Array
289
290      - file-name: "op_v_8_id_16"
291        description: Check that compiler reports an error when the register number is incorrect
292        isa:
293          instructions:
294            - sig: ldobj.64 v:in:ref, field_id
295              acc: out:b64
296              format: [op_v_8_id_16]
297        header-template: ['pandasm_header']
298        check-type: exit-positive
299        runner-options: ['compile-failure']
300        code-template: |
301
302          .function i32 main() {
303            ldobj.64 %s, R.fi64
304        cases:
305          - values: ['v255']
306            runner-options: ['compile-only']
307          - values: ['v256']
308          - values: ['v65535']
309          - values: ['a0']
310          - values: ['a1']
311          - values: ['null']
312          - values: ['1']
313          - values: ['"0"']
314
315      - file-name: "from_all_int_field_types"
316        description: Check that accumulator value is loaded from field into accumulator. More tests on ldobj.64 can be found in stobj.64 tests
317        isa:
318          instructions:
319            - sig: ldobj.64 v:in:ref, field_id
320              acc: out:b64
321              format: [op_v_8_id_16]
322        header-template: ['pandasm_header']
323        check-type: exit-positive
324        tags: ['tsan']
325        code-template: |
326
327          .function i32 main() {
328            initobj.short R.ctor
329            sta.obj v0
330            ldai.64 %s
331            stobj.64 v0, R.f%s
332            movi.64 v15, %s
333            ldobj.64 v0, R.f%s
334            %s v15
335            jeqz success
336            ldai 1
337            return
338          success:
339        cases:
340          # u64
341          - values: [0, 'u64', 0, 'u64', 'ucmp.64']
342          - values: [0xffffffffffffffff, 'u64', 0xffffffffffffffff, 'u64', 'ucmp.64']
343          - values: [0xa5a5a5a5a5a5a5a5, 'u64', 0xa5a5a5a5a5a5a5a5, 'u64', 'ucmp.64']
344          # i64
345          - values: [0, 'i64', 0, 'i64', 'cmp.64']
346          - values: [-1, 'i64', -1, 'i64', 'cmp.64']
347          - values: [-6510615555426900571, 'i64', -6510615555426900571, 'i64', 'cmp.64']
348
349      - file-name: "from_float_field_type"
350        description: Check that accumulator value is loaded from field into accumulator. More tests on ldobj.64 can be found in stobj.64 tests
351        isa:
352          instructions:
353            - sig: ldobj.64 v:in:ref, field_id
354              acc: out:b64
355              format: [op_v_8_id_16]
356        header-template: ['pandasm_header']
357        bugid: ['3292']
358        check-type: exit-positive
359        code-template: |
360
361          .function i32 main() {
362            initobj.short R.ctor
363            sta.obj v0
364            %s
365            stobj.64 v0, R.ff64
366            lda.null
367            %s
368            ldobj.64 v0, R.ff64
369            fcmpg.64 v15
370            %s
371            jeqz success
372            ldai 1
373            return
374          success:
375        cases:
376          # f64
377          - values: ['fldai.64 0.0', 'fmovi.64 v15, 0.0', '']
378          - values: ['fldai.64 -6510615555426900571.0', 'fmovi.64 v15, -6510615555426900571.0', '']
379          - values: ['fldai.64 0x7FFFFFFFFFFFFFFF', 'fmovi.64 v15, 0x7FFFFFFFFFFFFFFF', 'subi 1']    # NaN
380          - values: ['fldai.64 0x7ff0000000000000', 'fmovi.64 v15, 0x7ff0000000000000', '']    # + Inf
381          - values: ['fldai.64 0xfff0000000000000', 'fmovi.64 v15, 0xfff0000000000000', '']    # - Inf
382