# Copyright (c) 2021-2022 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. definitions: - name: PandaAssembly_header template: | .language PandaAssembly .record panda.Object .record panda.String .record panda.Exception .record panda.RuntimeException .record panda.ClassCastException .record panda.io.Serializable .record R <> {} .record I {} .record Q {} .record A {} - name: pandasm_header template: | .language PandaAssembly .record panda.Object .record panda.String .record panda.ClassCastException .record R {} .record Q {} tests: - file-name: "checkcast" isa: title: Check cast description: > Resolve object type by specified id and if an object in accumulator can be cast to the resolved type, accumulator content remains unchanged. Otherwise ClassCastException is thrown. instructions: - sig: checkcast type_id acc: in:ref format: [op_id_16] commands: - file-name: "null_to_any_type_pa" tags: ['tsan'] description: Check that null object reference can be cast to any type isa: description: > 'null' object reference can be cast to every type. header-template: ['pandasm_header'] check-type: empty code-template: | .function i32 main() { try_begin: lda.null %s try_end: jnez.obj set_failure # check that acc == null ldai 0 return set_failure: ldai 1 return catch_begin: ldai 2 return .catch panda.ClassCastException, try_begin, try_end, catch_begin } cases: - values: - checkcast panda.Object - values: - checkcast panda.String - values: - checkcast R - values: - | checkcast R checkcast Q - values: - | checkcast panda.ClassCastException checkcast R - file-name: "null_to_any_type_j" description: Check that null object reference can be cast to any type isa: description: > 'null' object reference can be cast to every type. header-template: ['PandaAssembly_header'] tags: ['irtoc_ignore'] check-type: empty runner-options: ['use-pa'] bugid: ["1720", "3967"] code-template: | .function i32 main() { try_begin: lda.null %s try_end: jnez.obj set_failure # check that acc == null ldai 0 return set_failure: ldai 1 return catch_begin: ldai 2 return .catch panda.ClassCastException, try_begin, try_end, catch_begin } cases: - values: - checkcast panda.Object - values: - checkcast panda.String - values: - checkcast R - values: - | checkcast panda.io.Serializable checkcast panda.String - values: - | checkcast I checkcast Q checkcast A - values: - | checkcast panda.ClassCastException checkcast R - file-name: "null_to_array_type_pa" description: Check that null object reference can be cast to any array type isa: description: > 'null' object reference can be cast to every type. header-template: ['pandasm_header'] check-type: empty bugid: ["1710"] code-template: | .function i32 main() { try_begin: lda.null %s try_end: jnez.obj set_failure # check that acc == null ldai 0 return set_failure: ldai 1 return catch_begin: ldai 2 return .catch panda.ClassCastException, try_begin, try_end, catch_begin } cases: - values: - checkcast panda.Object[] - values: - checkcast panda.String[] - values: - checkcast R[] - values: - | checkcast R[] checkcast Q[] - values: - | checkcast panda.ClassCastException[] checkcast R[] - file-name: "null_to_array_type_j" description: Check that null object reference can be cast to any array type isa: description: > 'null' object reference can be cast to every type. header-template: ['PandaAssembly_header'] check-type: empty tags: ['irtoc_ignore'] runner-options: ['use-pa'] bugid: ["1710"] code-template: | .function i32 main() { try_begin: lda.null %s try_end: jnez.obj set_failure # check that acc == null ldai 0 return set_failure: ldai 1 return catch_begin: ldai 2 return .catch panda.ClassCastException, try_begin, try_end, catch_begin } cases: - values: - checkcast panda.Object[] - values: - checkcast panda.String[] - values: - checkcast R[] - values: - | checkcast panda.io.Serializable[] checkcast panda.String[] - values: - | checkcast I[] checkcast Q[] checkcast A[] - values: - | checkcast panda.ClassCastException[] checkcast R[] - file-name: "against_base_type_pa" description: Check that any object can be cast to the base type isa: description: Object of type O can be cast to type T if O is the same as T or is subtype of T. header-template: ['pandasm_header'] check-type: empty tags: ['tsan'] code-template: | .function i32 main() { try_begin: %s %s checkcast panda.Object try_end: jne.obj v1, set_failure # check that acc isn't changed ldai 0 return catch_begin: ldai 2 return set_failure: ldai 1 return .catch panda.ClassCastException, try_begin, try_end, catch_begin } cases: - values: - newobj v1, panda.ClassCastException - lda.obj v1 - values: - newobj v1, R - lda.obj v1 - values: - lda.str "" - sta.obj v1 - values: - lda.str "abc" - sta.obj v1 - values: - lda.type R - sta.obj v1 - file-name: "against_base_type_j" description: Check that any object can be cast to the base type isa: description: Object of type O can be cast to type T if O is the same as T or is subtype of T. header-template: ['PandaAssembly_header'] check-type: empty tags: ['irtoc_ignore'] runner-options: ['use-pa'] code-template: | .function i32 main() { try_begin: %s %s checkcast panda.Object try_end: jne.obj v1, set_failure # check that acc isn't changed ldai 0 return catch_begin: ldai 2 return set_failure: ldai 1 return .catch panda.ClassCastException, try_begin, try_end, catch_begin } cases: - values: - newobj v1, panda.Exception - lda.obj v1 - values: - newobj v1, panda.String - lda.obj v1 - values: - newobj v1, R - lda.obj v1 - values: - newobj v1, Q - lda.obj v1 - values: - newobj v1, A - lda.obj v1 - values: - lda.str "" - sta.obj v1 - values: - lda.str "abc" - sta.obj v1 - values: - lda.type R - sta.obj v1 - values: - lda.type panda.Exception - sta.obj v1 - file-name: "against_same_type_pa" description: Check that any object can be cast to its type isa: description: Object of type O can be cast to type T if O is the same as T or is subtype of T. header-template: ['pandasm_header'] check-type: empty code-template: | .function i32 main() { %s %s try_begin: checkcast %s try_end: jne.obj v1, set_failure # check that acc hasn't been changed ldai 0 return catch_begin: ldai 2 return set_failure: ldai 1 return .catch panda.ClassCastException, try_begin, try_end, catch_begin } cases: - values: - newobj v1, panda.ClassCastException - lda.obj v1 - panda.ClassCastException - values: - newobj v1, R - lda.obj v1 - R - values: - lda.str "" - sta.obj v1 - panda.String - values: - lda.str "abc" - sta.obj v1 - panda.String - file-name: "against_same_type_j" description: Check that any object can be cast to its type isa: description: Object of type O can be cast to type T if O is the same as T or is subtype of T. header-template: ['PandaAssembly_header'] check-type: empty runner-options: ['use-pa'] tags: ['tsan', 'irtoc_ignore'] code-template: | .function i32 main() { %s %s try_begin: checkcast %s try_end: jne.obj v1, set_failure # check that acc hasn't been changed ldai 0 return catch_begin: ldai 2 return set_failure: ldai 1 return .catch panda.ClassCastException, try_begin, try_end, catch_begin } cases: - values: - newobj v1, panda.Exception - lda.obj v1 - panda.Exception - values: - newobj v1, panda.RuntimeException - lda.obj v1 - panda.RuntimeException - values: - newobj v1, R - lda.obj v1 - R - values: - newobj v1, Q - lda.obj v1 - Q - values: - newobj v1, A - lda.obj v1 - A - values: - lda.str "" - sta.obj v1 - panda.String - values: - lda.str "abc" - sta.obj v1 - panda.String - file-name: "against_supertype_j" description: Check that any object can be cast to its supertype isa: description: Object of type O can be cast to type T if O is the same as T or is subtype of T. header-template: ['PandaAssembly_header'] check-type: empty tags: ['irtoc_ignore'] runner-options: ['use-pa'] code-template: | .function i32 main() { try_begin: newobj v1, %s lda.obj v1 checkcast %s try_end: jne.obj v1, set_failure # check that acc hasn't been changed ldai 0 return set_failure: ldai 1 return catch_begin: ldai 2 return .catch panda.ClassCastException, try_begin, try_end, catch_begin } cases: - values: - panda.RuntimeException - panda.Exception - values: - Q - R - values: - Q - I - file-name: "array_against_base_type_pa" description: Check that any array can be cast to base type isa: description: > Object of type O can be cast to type T if O is the same as T or is subtype of T. For arrays O can be cast to T if T is a root type in type hierarchy or T is such array that O array elements are the same or subtype of T array elements. header-template: ['pandasm_header'] check-type: empty code-template: | .function i32 main() { try_begin: movi v0, 10 newarr v1, v0, %s[] lda.obj v1 checkcast panda.Object try_end: jne.obj v1, set_failure # check that acc isn't changed ldai 0 return set_failure: ldai 1 return catch_begin: ldai 2 return .catch panda.ClassCastException, try_begin, try_end, catch_begin } cases: - values: - panda.ClassCastException - values: - R - values: - panda.String - file-name: "array_against_base_type_j" description: Check that any array can be cast to base type isa: description: > Object of type O can be cast to type T if O is the same as T or is subtype of T. For arrays O can be cast to T if T is a root type in type hierarchy or T is such array that O array elements are the same or subtype of T array elements. header-template: ['PandaAssembly_header'] tags: ['irtoc_ignore'] check-type: empty runner-options: ['use-pa'] code-template: | .function i32 main() { try_begin: movi v0, 10 newarr v1, v0, %s[] lda.obj v1 checkcast panda.Object try_end: jne.obj v1, set_failure # check that acc isn't changed ldai 0 return set_failure: ldai 1 return catch_begin: ldai 2 return .catch panda.ClassCastException, try_begin, try_end, catch_begin } cases: - values: - panda.Exception - values: - panda.String - values: - R - values: - Q - values: - A - file-name: "array_against_its_type_pa" description: Check that any array can be cast to its type isa: description: > For arrays O can be cast to T if T is a root type in type hierarchy or T is such array that O array elements are the same or subtype of T array elements. header-template: ['pandasm_header'] check-type: empty bugid: ["1710"] code-template: | .function i32 main() { try_begin: movi v0, 10 newarr v1, v0, %s[] lda.obj v1 checkcast %s[] try_end: jne.obj v1, set_failure # check that acc isn't changed ldai 0 return set_failure: ldai 1 return catch_begin: ldai 2 return .catch panda.ClassCastException, try_begin, try_end, catch_begin } cases: - values: - panda.ClassCastException - panda.ClassCastException - values: - R - R - values: - panda.String - panda.String - file-name: "array_against_its_type_j" description: Check that any array can be cast to its type isa: description: > For arrays O can be cast to T if T is a root type in type hierarchy or T is such array that O array elements are the same or subtype of T array elements. header-template: ['PandaAssembly_header'] tags: ['irtoc_ignore'] check-type: empty runner-options: ['use-pa'] bugid: ["1710"] code-template: | .function i32 main() { try_begin: movi v0, 10 newarr v1, v0, %s[] lda.obj v1 checkcast %s[] try_end: jne.obj v1, set_failure # check that acc isn't changed ldai 0 return set_failure: ldai 1 return catch_begin: ldai 2 return .catch panda.ClassCastException, try_begin, try_end, catch_begin } cases: - values: - panda.RuntimeException - panda.RuntimeException - values: - R - R - values: - Q - Q - values: - A - A - values: - panda.String - panda.String - file-name: "array_against_basetype_array_pa" description: Check that any array can be cast to base type array isa: description: > For arrays O can be cast to T if T is a root type in type hierarchy or T is such array that O array elements are the same or subtype of T array elements. header-template: ['pandasm_header'] check-type: empty bugid: ["1710"] code-template: | .function i32 main() { try_begin: movi v0, 10 newarr v1, v0, %s[] lda.obj v1 checkcast panda.Object[] try_end: jne.obj v1, set_failure # check that acc isn't changed ldai 0 return set_failure: ldai 1 return catch_begin: ldai 2 return .catch panda.ClassCastException, try_begin, try_end, catch_begin } cases: - values: - panda.ClassCastException - values: - R - values: - panda.String - file-name: "array_against_basetype_array_j" description: Check that any array can be cast to base type array isa: description: > For arrays O can be cast to T if T is a root type in type hierarchy or T is such array that O array elements are the same or subtype of T array elements. header-template: ['PandaAssembly_header'] check-type: empty tags: ['irtoc_ignore'] runner-options: ['use-pa'] bugid: ["1710"] code-template: | .function i32 main() { try_begin: movi v0, 10 newarr v1, v0, %s[] lda.obj v1 checkcast panda.Object[] try_end: jne.obj v1, set_failure # check that acc isn't changed ldai 0 return set_failure: ldai 1 return catch_begin: ldai 2 return .catch panda.ClassCastException, try_begin, try_end, catch_begin } cases: - values: - panda.RuntimeException - values: - R - values: - Q - values: - A - values: - panda.String - file-name: "array_against_supertype_array_j" description: Check that any array can be cast to its supertype array tags: ['tsan', 'irtoc_ignore'] isa: description: > For arrays O can be cast to T if T is a root type in type hierarchy or T is such array that O array elements are the same or subtype of T array elements. header-template: ['PandaAssembly_header'] check-type: empty runner-options: ['use-pa'] bugid: ["1710"] code-template: | .function i32 main() { try_begin: movi v0, 10 newarr v1, v0, %s[] lda.obj v1 checkcast %s[] try_end: jne.obj v1, set_failure # check that acc isn't changed ldai 0 return catch_begin: ldai 2 return set_failure: ldai 1 return .catch panda.ClassCastException, try_begin, try_end, catch_begin } cases: - values: - panda.RuntimeException - panda.Exception - values: - Q - R - values: - Q - I - file-name: "against_other_type_j" description: Check that ClassCastException is thrown when object cannot be cast to a type isa: description: > Otherwise ClassCastException is thrown. Object of type O can be cast to type T if O is the same as T or is subtype of T. For arrays O can be cast to T if T is a root type in type hierarchy or T is such array that O array elements are the same or subtype of T array elements. exceptions: - x_cast tags: ['irtoc_ignore'] header-template: ['PandaAssembly_header'] check-type: empty runner-options: ['use-pa'] bugid: ["1710", "3967"] code-template: | .function i32 main() { try_begin: %s checkcast %s ldai 1 return try_end: ldai 0 return .catch panda.ClassCastException, try_begin, try_end, try_end } cases: - values: - | newobj v0, panda.RuntimeException lda.obj v0 - panda.RuntimeException[] - values: - | newobj v0, panda.RuntimeException lda.obj v0 - panda.Exception[] - values: - | newobj v0, R lda.obj v0 - panda.io.Serializable - values: - | newobj v0, Q lda.obj v0 - Q[] - values: - | newobj v0, Q lda.obj v0 - R[] - values: - | newobj v0, panda.Exception lda.obj v0 - panda.RuntimeException - values: - | newobj v0, R lda.obj v0 - Q - values: - lda.type R - R - file-name: "against_other_type_pa" description: Check that ClassCastException is thrown when object cannot be cast to a type isa: description: > Otherwise ClassCastException is thrown. Object of type O can be cast to type T if O is the same as T or is subtype of T. For arrays O can be cast to T if T is a root type in type hierarchy or T is such array that O array elements are the same or subtype of T array elements. exceptions: - x_cast header-template: ['pandasm_header'] tags: ['irtoc_ignore'] check-type: empty code-template: | .function i32 main() { try_begin: %s checkcast %s ldai 1 return try_end: ldai 0 return .catch panda.ClassCastException, try_begin, try_end, try_end } cases: - values: - | newobj v0, Q lda.obj v0 - Q[] bugid: ["1710"] - values: - | newobj v0, Q lda.obj v0 - R[] bugid: ["1710"] - values: - | newobj v0, R lda.obj v0 - Q - values: - lda.str "" - panda.ClassCastException - values: - lda.str "abc" - R - values: - lda.type R - R - file-name: "array_against_other_type_pa" description: Check that ClassCastException is thrown when array cannot be cast to a type isa: description: > Otherwise ClassCastException is thrown. Object of type O can be cast to type T if O is the same as T or is subtype of T. For arrays O can be cast to T if T is a root type in type hierarchy or T is such array that O array elements are the same or subtype of T array elements. exceptions: - x_cast header-template: ['pandasm_header'] tags: ['irtoc_ignore'] check-type: empty code-template: | .function i32 main() { try_begin: movi v0, 10 newarr v0, v0, %s lda.obj v0 checkcast %s ldai 1 return try_end: ldai 0 return .catch panda.ClassCastException, try_begin, try_end, try_end } cases: - values: - Q[] - Q - values: - Q[] - R - values: - R[] - Q[] bugid: ["1710"] - values: - panda.String[] - panda.ClassCastException[] bugid: ["1710"] - file-name: "array_against_other_type_j" description: Check that ClassCastException is thrown when array cannot be cast to a type isa: description: > Otherwise ClassCastException is thrown. Object of type O can be cast to type T if O is the same as T or is subtype of T. For arrays O can be cast to T if T is a root type in type hierarchy or T is such array that O array elements are the same or subtype of T array elements. exceptions: - x_cast header-template: ['PandaAssembly_header'] tags: ['irtoc_ignore'] check-type: empty runner-options: ['use-pa'] bugid: ["1710", "1720", "3967"] code-template: | .function i32 main() { try_begin: movi v0, 10 newarr v0, v0, %s lda.obj v0 checkcast %s ldai 1 return try_end: ldai 0 return .catch panda.ClassCastException, try_begin, try_end, try_end } cases: - values: - panda.RuntimeException[] - panda.RuntimeException - values: - panda.RuntimeException[] - panda.Exception - values: - panda.io.Serializable[] - R[] bugid: ['1806'] - values: - Q[] - Q - values: - Q[] - R - values: [ "panda.Exception[]", "panda.RuntimeException[]"] - values: - R[] - Q[] - file-name: "with_wrong_acc_value_pa" description: Check that verification fails when accumulator contains wrong value, not an object or null isa: verification: - acc_obj_or_null header-template: ['pandasm_header'] check-type: empty tags: ['verifier'] runner-options: ['verifier-failure', 'verifier-config'] code-template: | .function i32 main() { %s checkcast panda.Object ldai 0 return } cases: - values: - ldai -1 - values: - ldai.64 1 - values: - fldai.64 -1.1 - file-name: "with_wrong_acc_value_j" description: Check that verification fails when accumulator contains wrong value, not an object or null isa: verification: - acc_obj_or_null header-template: ['PandaAssembly_header'] check-type: empty runner-options: ['use-pa', 'verifier-failure', 'verifier-config'] tags: [verifier, pa-verifier] bugid: ['6886'] code-template: | .function i32 main() { %s checkcast panda.Object ldai 0 return } cases: - values: - ldai -1 - values: - ldai.64 1 - values: - fldai.64 -1.1 - file-name: "with_wrong_type_id_pa" description: Check that verification fails when accumulator contains wrong value, not an object or null isa: verification: - type_id_any_object header-template: ['pandasm_header'] check-type: empty runner-options: ['compile-failure'] code-template: | .function i32 main() { newobj v0, panda.Object lda.obj v0 checkcast %s ldai 0 return } cases: - values: - "0x7fffffff" - values: - "0x1234567890" - values: - 3.1415926 - values: - "\"abc\"" - file-name: "with_wrong_type_id_j" description: Check that verification fails when accumulator contains wrong value, not an object or null isa: instructions: - sig: checkcast type_id acc: in:ref format: [op_id_16] verification: - type_id_any_object header-template: ['PandaAssembly_header'] check-type: empty runner-options: ['use-pa', 'compile-failure'] code-template: | .function i32 main() { newobj v0, panda.Object lda.obj v0 checkcast %s ldai 0 return } cases: - values: - "0x7fffffff" - values: - "0x1234567890" - values: - 3.1415926 - values: - "\"abc\""