• 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: []
15tests:
16  - file-name: "jgtz"
17    isa:
18      title: Conditional compared to zero jump
19      description: >
20        Transfer execution to an instruction at offset bytes
21        from the beginning of the current instruction
22        if signed 32-bit integer in accumulator compares with 0 as specified.
23        Offset is sign extended to the size of instruction address.
24      exceptions:
25        - x_none
26    commands:
27
28      - file-name: "op"
29        isa:
30          instructions:
31            - sig: jgtz imm:i32
32              acc: in:i32
33              format: [op_imm_8, op_imm_16]
34        description: >
35          Check jump occurs or not occurs, depending on `acc < 0` condition
36          for forward, backward, or current cases.
37        code-template: |
38          #
39              %s
40        check-type: exit-positive
41        cases:
42          - values:
43            - |
44              # Check forward jump
45                  ldai 0x7FFFFFFF
46                  jgtz label
47                  ldai 255 ##*65536
48                  return  # should be jumped over
49              label:
50          - values:
51            - |
52              # Check backward jump
53                  jmp label2
54              label1:
55                  jmp label3
56                  ldai 255 ##*65536
57              label2:
58                  ldai 1
59                  jgtz label1
60                  ldai 255
61                  return  # should be jumped over
62              label3:
63          - values:
64              - |
65                # Check jump to itself
66                    ldai 0
67                loop:
68                    jgtz loop
69            bugid: ['3468']
70          - values:
71              - |
72                # Check jump to itself
73                    ldai 1
74                loop:
75                    jgtz loop
76            runner-options: [compile-only]
77
78      - file-name: "op_bounds"
79        isa:
80          instructions:
81            - sig: jgtz imm:i32
82              acc: in:i32
83              format: [op_imm_8, op_imm_16]
84        description: >
85          Check jump occurs or not occurs, depending on `acc > 0` condition
86          for forward and backward cases.
87        code-template: |
88          #
89              %s
90        check-type: none
91        cases:
92          - values:
93            - |
94              # Max forward jump for imm8, 2 + 124 + 1 = 127 bytes
95                  ldai 1
96                  jgtz label    # 2-byte instruction
97                  ldai 1 ##*62
98                  return
99              label:
100                  ldai 0
101                  return
102          - values:
103            - |
104              # Max backward jump for imm8, 2 + 61*2 + 1 + 1 + 2 = 128 bytes
105                  jmp label2
106              label:
107                  ldai 61
108                  subi 1 ##*61
109                  return
110                  return
111              label2:
112                  ldai 1
113                  jgtz label
114                  return
115          - values:
116            - |
117              # Max forward jump for imm16, 3 + 32760 + 4 = 32767 bytes
118                  ldai 1
119                  jgtz label    # 3-byte instruction
120                  movi.64 v0, 0 ##*3276
121                  addi 3
122                  return
123                  return
124              label:
125                  ldai 0
126                  return
127          - values:
128            - |
129              # Max backward jump for imm16, 1 + 4 + 32760 + 1 + 2 = 32768 bytes
130                  jmp label2
131              label:
132                  ldai 0
133                  return
134                  ldai 1
135                  movi.64 v0, 0 ##*3276
136                  return
137              label2:
138                  ldai 1
139                  jgtz label
140                  return
141
142      - file-name: "vals"
143        isa:
144          instructions:
145            - sig: jgtz imm:i32
146              acc: in:i32
147              format: [op_imm_8, op_imm_16]
148        description: >
149          Check jump not occurs if `acc <= 0`
150          for different values in acc.
151        code-template: |
152          #
153              ldai %s
154              jgtz label_bad
155              ldai *s
156              jgtz label_good
157          label_bad:
158              ldai 255
159              return  # should be jumped over
160          label_good:
161        check-type: exit-positive
162        template-cases:
163          - values:
164              - "0"
165            exclude: [one]
166          - values:
167              - "-1"
168            exclude: [max]
169          - values:
170              - "0x80000000"
171            exclude: [one]
172          - values:
173              - "0xFFFFFFFF"
174            exclude: [max]
175        cases:
176          - values:
177              - "1"
178            id: one
179          - values:
180              - "0x7FFFFFFF"
181            id: max
182
183      - file-name: "type"
184        isa:
185          instructions:
186            - sig: jgtz imm:i32
187              acc: in:i32
188              format: [op_imm_8, op_imm_16]
189          verification:
190              - acc_type
191        description: >
192          Check `jgtz` with invalid types in acc.
193        tags: ['verifier']
194        runner-options: ['verifier-failure', 'verifier-config']
195        header-template: []
196        code-template: |
197          #
198          .record A {}
199          .record panda.String <external>
200          .record panda.Object <external>
201          .function i32 main() {
202              %s
203              jgtz label
204              ldai 255
205          label:
206        check-type: exit-positive
207        cases:
208          - values:
209              - lda.null
210          - values:
211              - ldai.64 0
212          - values:
213              - fldai 0
214          - values:
215              - fldai.64 0
216          - values:
217              - lda.type A
218          - values:
219              - lda.type A[]
220          - values:
221              - lda.type panda.String
222          - values:
223              - |
224                newobj v0, A
225                lda.obj v0
226          - values:
227              - |
228                newobj v0, panda.Object
229                lda.obj v0
230          - values:
231              - lda.str "0"
232          - values:
233              - |
234                #
235                    movi v0, 10
236                    newarr v0, v0, i32[]
237                    lda.obj v0
238
239      - file-name: "outside_function"
240        isa:
241          instructions:
242            - sig: jgtz imm:i32
243              acc: in:i32
244              format: [op_imm_8, op_imm_16]
245          verification:
246            - branch_target
247        description: >
248          Branch target should point to a beginning
249          of an instruction of the same method.
250        runner-options: ['compile-failure']
251        header-template: []
252        code-template: |
253          #
254          .function i32 f() {
255          label:
256              ldai 255
257              return
258          }
259          .function i32 main() {
260              ldai -1
261              jgtz label
262        check-type: exit-positive
263
264      - file-name: "outside_try_catch_p"
265        isa:
266          instructions:
267            - sig: jgtz imm:i32
268              acc: in:i32
269              format: [op_imm_8, op_imm_16]
270        description: Jump outside try/catch block.
271        bugid: ['3425']
272        header-template: []
273        code-template: |
274          .record panda.ArithmeticException <external>
275          .function i32 main() {
276          begin:
277              ldai 1
278              jgtz outside
279              newobj v0, panda.ArithmeticException
280              throw v0
281          end:
282              ldai 1
283              return
284          catch_ae:
285              ldai 2
286              return
287          .catch panda.ArithmeticException, begin, end, catch_ae
288              ldai 3
289              return
290          outside:
291        check-type: exit-positive
292
293      - file-name: "outside_try_catch_j"
294        isa:
295          instructions:
296            - sig: jgtz imm:i32
297              acc: in:i32
298              format: [op_imm_8, op_imm_16]
299        description: Jump outside try/catch block.
300        bugid: ['3425']
301        header-template: []
302        runner-options: ['use-pa']
303        code-template: |
304          .language PandaAssembly
305          .record panda.NullPointerException <external>
306          .function i32 main() {
307          begin:
308              ldai 1
309              jgtz outside
310              mov.null v0
311              throw v0
312          end:
313              ldai 1
314              return
315          catch_npe:
316              ldai 2
317              return
318          .catch panda.NullPointerException, begin, end, catch_npe
319              ldai 3
320              return
321          outside:
322        check-type: exit-positive
323
324      - file-name: uninitialized_regs
325        isa:
326          instructions:
327            - sig: jgtz imm:i32
328              acc: in:i32
329              format: [op_imm_8, op_imm_16]
330        description: Check `jgtz` with uninitialized acc.
331        tags: ['verifier']
332        runner-options: ['verifier-failure', 'verifier-config']
333        code-template: |
334          #
335          label:
336              jgtz label
337        check-type: exit-positive
338
339      - file-name: "invalid_branch_target"
340        isa:
341          verification:
342            - branch_target
343        runner-options: [compile-failure]
344        description: Check 'jgtz' instruction with invalid branch target.
345        header-template: []
346        code-template: |
347            .record R {}
348
349            .function void R.ctor(R a0) <ctor> {
350            lbl_ctor:
351                return.void
352            }
353
354            .function void R.cctor() <cctor> {
355            lbl_cctor:
356                return.void
357            }
358
359            .function i32 foo(i32 a0, i32 a1) <static> {
360                lda a0
361                jgtz %s
362                return
363            }
364
365            .function i32 bar() <static> {
366            lbl_bar:
367                ldai 1
368                return
369            }
370
371            .function i32 main() {
372                movi v0, 0
373                movi v1, 1
374                call.short foo, v0, v1
375            lbl_main:
376        check-type: exit-positive
377        cases:
378          - values: ["main"]
379          - values: ["foo"]
380          - values: ["bar"]
381          - values: ["baz"]
382          - values: ["R"]
383          - values: ["lbl_main"]
384          - values: ["lbl_bar"]
385          - values: ["lbl_ctor"]
386          - values: ["lbl_cctor"]
387
388
389      - file-name: "prohibited_branch_target"
390        isa:
391          verification:
392            - branch_target
393        runner-options: ['verifier-failure', 'verifier-config']
394        tags: [verifier]
395        description: Check 'jgtz' instruction with prohibited branch target.
396        header-template: []
397        code-template: |
398            .record E1 {}
399            .record E2 {}
400
401            .function i32 main() {
402                ldai 1
403                jgtz %s
404
405            begin:
406                ldai 0
407                return
408            mid:
409                ldai 1
410                return
411            end:
412                ldai 2
413                return
414
415            catch_E1_begin:
416                ldai 3
417                return
418            catch_E1_mid:
419                ldai 4
420                return
421            catch_E1_end:
422                ldai 5
423                return
424
425            catch_E2_begin:
426                ldai 6
427                return
428            catch_E2_mid:
429                ldai 7
430                return
431            catch_E2_end:
432
433            quit:
434                ldai 8
435                return
436
437            .catch E1, begin, end, catch_E1_begin, catch_E1_end
438            .catch E2, catch_E1_begin, catch_E1_end, catch_E2_begin, catch_E2_end
439            outside:
440        check-type: none
441        cases:
442          - values: ["begin"]
443            runner-options: ['verifier-only', 'verifier-config']
444          - values: ["mid"]
445            runner-options: ['verifier-only', 'verifier-config']
446          - values: ["end"]
447            runner-options: ['verifier-only', 'verifier-config']
448          - values: ["quit"]
449            runner-options: ['verifier-only', 'verifier-config']
450          - values: ["catch_E1_begin"]
451          - values: ["catch_E1_mid"]
452          - values: ["catch_E1_end"]
453            runner-options: ['verifier-only', 'verifier-config']
454          - values: ["catch_E2_begin"]
455          - values: ["catch_E2_mid"]
456          - values: ["catch_E2_end"]
457            runner-options: ['verifier-only', 'verifier-config']
458          - values: ["outside"]
459