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: 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 # objects 39 i32[] fi32Array 40 Q fQ 41 Q[] fQArray 42 R fR 43 R[] fRArray 44 panda.Object fObj 45 panda.Object[] fObjArray 46 } 47 .function void R.ctor(R a0) <ctor> { 48 return.void 49 } 50 51 - name: java_header 52 template: | 53 .language Java 54 55 .record java.lang.Object <external> 56 .function void java.lang.Object.ctor(java.lang.Object a0) <external, ctor> 57 58 .record I <java.interface> {} 59 60 .record Q <java.implements=I> {} 61 .function void Q.ctor(Q a0) <ctor> { 62 return.void 63 } 64 65 .record R <java.extends=Q> { 66 u1 fu1 67 u8 fu8 68 i8 fi8 69 u16 fu16 70 i16 fi16 71 u32 fu32 72 i32 fi32 73 u64 fu64 74 i64 fi64 75 f32 ff32 76 f64 ff64 77 # objects 78 i32[] fi32Array 79 Q fQ 80 Q[] fQArray 81 R fR 82 R[] fRArray 83 I fI 84 I[] fIArray 85 java.lang.Object fObj 86 java.lang.Object[] fObjArray 87 } 88 .function void R.ctor(R a0) <ctor> { 89 return.void 90 } 91 92tests: 93 - file-name: "stobj.obj" 94 isa: 95 title: Store accumulator content into object field 96 description: > 97 Store accumulator content into object field by field_id. 98 instructions: 99 - sig: stobj.obj v:in:ref, field_id 100 acc: in:ref 101 format: [op_v_8_id_16] 102 commands: 103 104 - file-name: "check_if_regs_initialized" 105 description: Check that verifier reports error if source registers are not initialized 106 isa: 107 description: Store accumulator content into object field by field_id. 108 header-template: ['pandasm_header'] 109 check-type: exit-positive 110 tags: ['verifier'] 111 bugid: ['1324'] 112 runner-options: ['verifier-failure', 'verifier-debug-config'] 113 code-template: | 114 115 %s 116 117 .function i32 main() { 118 initobj R.ctor 119 sta.obj v0 120 call.short check, v0 121 cases: 122 - values: 123 - | 124 # acc (value) not initialized in the frame 125 .function void check(R a0) { 126 stobj.obj a0, R.fR 127 return.void 128 } 129 - values: 130 - | 131 # v0 (object) not initialized in the frame 132 .function void check(R a0) { 133 lda.obj a0 134 stobj.obj v0, R.fR 135 return.void 136 } 137 bugid: ['1324'] 138 139 - file-name: "with_null_ref_pa" 140 description: Check that NullPointerException is thrown if source ref is null 141 isa: 142 exceptions: 143 - x_null 144 header-template: ['pandasm_header'] 145 check-type: empty 146 tags: ['arm64-jit'] 147 bugid: ['3047'] 148 code-template: | 149 .record panda.NullPointerException <external> 150 151 .function R get_null() { 152 lda.null 153 return.obj 154 } 155 156 .function i32 main() { 157 call.short get_null 158 sta.obj v0 159 %s 160 try_begin: 161 stobj.obj v0, %s 162 ldai 1 163 return 164 try_end: 165 ldai 0 166 return 167 .catch panda.NullPointerException, try_begin, try_end, try_end 168 } 169 cases: 170 - values: 171 - lda.null 172 - R.fR 173 - values: 174 - initobj Q.ctor 175 - R.fQ 176 - values: 177 - | 178 movi v1, 10 179 newarr v1, v1, i32[] 180 lda.obj v1 181 - R.fi32Array 182 183 - file-name: "with_non_object_ref_pa" 184 description: Check that verifier reports error when the 1st operand is not a ref to an object (other than array) 185 isa: 186 verification: 187 - v1_object 188 header-template: ['pandasm_header'] 189 check-type: empty 190 tags: ['verifier'] 191 bugid: ['1324', '1826', '1827'] 192 runner-options: ['verifier-failure', 'verifier-debug-config'] 193 code-template: | 194 195 .function i32 main() { 196 %s 197 initobj Q.ctor 198 try_begin: 199 stobj.obj v0, R.fQ 200 try_end: 201 ldai 0 202 return 203 .catchall try_begin, try_end, try_end 204 } 205 cases: 206 - values: 207 - movi v0, 0 208 209 - values: 210 - movi v0, 1 211 - values: 212 - movi.64 v0, 0x00 213 - values: 214 - movi.64 v0, 0xCAFECAFECAFECAFE 215 - values: 216 - fmovi.64 v0, 0.0 217 - values: 218 - fmovi.64 v0, 6.62607015 219 - values: 220 - | 221 movi v1, 10 222 newarr v0, v1, R[] 223 224 - file-name: "with_static_field_id_pa" 225 description: Check that verifier reports error when the field doesn't resolve to a non-static object field 226 isa: 227 verification: 228 - field_id_non_static 229 header-template: ['pandasm_header'] 230 check-type: exit-positive 231 bugid: ['1324', '1828', '1833'] 232 tags: ['verifier'] 233 runner-options: ['verifier-failure', 'verifier-debug-config'] 234 code-template: | 235 .record W { 236 W static_field <static> 237 W[] static_array <static> 238 } 239 .function void W.ctor(W a0) <ctor> { 240 return.void 241 } 242 .function void W.foo(W a0) { 243 return.void 244 } 245 246 .record random_record_name { 247 W random_field_name 248 } 249 250 .function void random_function_name() { 251 return.void 252 } 253 254 .function i32 main() { 255 initobj W.ctor 256 sta.obj v0 257 lda.null 258 stobj.obj v0, %s 259 cases: 260 # resolves to a static object field 261 - values: 262 - W.static_field 263 # resolves to a static object array 264 - values: 265 - W.static_array 266 # resolves to a non-existing object field 267 - values: 268 - W.field_not_exists 269 runner-options: ['compile-failure'] 270 # resolves to object's constructor 271 - values: 272 - W.ctor 273 runner-options: ['compile-failure'] 274 # resolves to objects's method 275 - values: 276 - W.foo 277 runner-options: ['compile-failure'] 278 # resolves to some other object 279 - values: 280 - random_record_name 281 runner-options: ['compile-failure'] 282 # resolves to some static function 283 - values: 284 - random_function_name 285 runner-options: ['compile-failure'] 286 # resolves to a field name in a wrong object 287 - values: 288 - random_record_name.random_field_name 289 bugid: ['3536'] 290 ignore: true 291 # cannot resolve, because it's a i32 number 292 - values: 293 - 0 294 runner-options: ['compile-failure'] 295 # cannot resolve, because it's a f64 number 296 - values: 297 - -1.1 298 runner-options: ['compile-failure'] 299 # cannot resolve, because it's a "null" string 300 - values: 301 - "null" 302 runner-options: ['compile-failure'] 303 304 - file-name: "with_wrong_acc_type_pa" 305 description: Check that verifier reports error when the accumulator contains a value of type not corresponding to the bytecode 306 isa: 307 verification: 308 - acc_type 309 header-template: ['pandasm_header'] 310 check-type: exit-positive 311 tags: ['verifier'] 312 runner-options: ['verifier-failure', 'verifier-debug-config'] 313 code-template: | 314 315 .function i32 main() { 316 initobj R.ctor 317 sta.obj v0 318 %s 319 stobj.obj v0, %s 320 cases: 321 # store into object field 322 - values: 323 - ldai 0 324 - R.fQ 325 bugid: ['1324', '1834'] 326 - values: 327 - ldai.64 1 328 - R.fQ 329 bugid: ['1324', '1834'] 330 - values: 331 - fldai.64 0x7FFFFFFFFFFFFFFF 332 - R.fQ 333 bugid: ['1324', '1834'] 334 - values: 335 - lda.type R 336 - R.fQ 337 bugid: ['1834'] 338 - values: 339 - | 340 movi v1, 10 341 newarr v1, v1, Q[] 342 lda.obj v1 343 - R.fQ 344 bugid: ['1834'] 345 # store into object array field 346 - values: 347 - ldai 0 348 - R.fQArray 349 bugid: ['1324', '1834'] 350 - values: 351 - ldai.64 1 352 - R.fQArray 353 bugid: ['1324', '1834'] 354 - values: 355 - fldai.64 0x7FFFFFFFFFFFFFFF 356 - R.fQArray 357 bugid: ['1324', '1834'] 358 - values: 359 - initobj Q.ctor 360 - R.fQArray 361 bugid: ['1834'] 362 - values: 363 - | 364 movi v1, 10 365 newarr v1, v1, R[] 366 lda.obj v1 367 - R.fQArray 368 bugid: ['1834'] 369 # store into i32[] array field 370 - values: 371 - ldai 0 372 - R.fi32Array 373 bugid: ['1324', '1834'] 374 - values: 375 - ldai.64 1 376 - R.fi32Array 377 bugid: ['1324', '1834'] 378 - values: 379 - fldai.64 0x7FFFFFFFFFFFFFFF 380 - R.fi32Array 381 bugid: ['1324', '1834'] 382 - values: 383 - lda.type R 384 - R.fi32Array 385 bugid: ['1834'] 386 - values: 387 - | 388 movi v1, 10 389 newarr v1, v1, Q[] 390 lda.obj v1 391 - R.fi32Array 392 bugid: ['1834'] 393 394 - file-name: "op_v_8_id_16" 395 description: Check that compiler reports error when the register number is out of 8 bit size 396 isa: 397 instructions: 398 - sig: stobj.obj v:in:ref, field_id 399 acc: in:ref 400 format: [op_v_8_id_16] 401 header-template: ['pandasm_header'] 402 check-type: exit-positive 403 code-template: | 404 405 .function i32 main() { 406 stobj.obj %s, R.fQ 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 - file-name: "into_all_field_types_pa" 416 description: Check that accumulator value is stored in field 417 isa: 418 description: Store accumulator content into object field by field_id. 419 header-template: ['pandasm_header'] 420 check-type: exit-positive 421 tags: ['tsan'] 422 code-template: | 423 424 .function i32 main() { 425 initobj R.ctor 426 sta.obj v0 427 %s 428 sta.obj v7 429 stobj.obj v0, R.%s 430 lda.null 431 ldobj.obj v0, R.%s 432 jeq.obj v7, success 433 ldai 1 434 return 435 success: 436 cases: 437 - values: 438 - | 439 # store null into Q type field 440 lda.null 441 - fQ 442 - fQ 443 - values: 444 - | 445 # store null into Q[] type field 446 lda.null 447 - fQArray 448 - fQArray 449 - values: 450 - | 451 # store Q into Q type field 452 initobj Q.ctor 453 - fQ 454 - fQ 455 - values: 456 - | 457 # store Q[] into Q[] type field 458 movi v1, 10 459 newarr v1, v1, Q[] 460 lda.obj v1 461 - fQArray 462 - fQArray 463 464