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: 15 - name: PandaAssembly_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 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 panda.Object fObj 40 panda.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-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 v240, R.ff64' 120 - values: 121 - 'ldobj.64 v255, R.fu64' 122 123 124 - file-name: "check_if_regs_initialized_j" 125 description: Check that verifier reports error if source registers are not initialized in PandaAssembly context. 126 isa: 127 instructions: 128 - sig: ldobj.64 v:in:ref, field_id 129 acc: out:b64 130 format: [op_v_8_id_16] 131 header-template: ['PandaAssembly_header'] 132 check-type: exit-positive 133 tags: [verifier, pa-verifier] 134 bugid: ['1324', '2084', '3257', '3293'] 135 runner-options: ['verifier-failure', 'verifier-config', 'use-pa'] 136 code-template: | 137 138 .function i32 main() { 139 %s # verifier error expected, because the register is not initialized 140 cases: 141 - values: 142 - 'ldobj.64 v1, R.fi64' 143 - values: 144 - 'ldobj.64 v240, R.ff64' 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', 'irtoc_ignore'] 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.64 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 178 179 - file-name: "with_null_ref_j" 180 description: Check that NullPointerException is thrown if object ref is null in PandaAssembly context. 181 isa: 182 exceptions: 183 - x_null 184 runner-options: [use-pa] 185 header-template: ['PandaAssembly_header', 'get_null_R'] 186 check-type: empty 187 tags: ['tsan', 'irtoc_ignore'] 188 code-template: | 189 .record panda.NullPointerException <external> 190 191 .function i32 main() { 192 call.short get_null_R 193 sta.obj v0 194 try_begin: 195 ldobj.64 v0, %s 196 ldai 1 197 return 198 try_end: 199 ldai 0 200 return 201 .catch panda.NullPointerException, try_begin, try_end, try_end 202 } 203 cases: 204 - values: 205 - R.fi64 206 - values: 207 - R.ff64 208 209 210 - file-name: "with_non_object_ref_p" 211 description: Check that verifier reports an error when the 1st operand is not a ref to an object (other than array) in Panda context. 212 isa: 213 verification: 214 - v1_object 215 header-template: ['pandasm_header'] 216 check-type: exit-positive 217 tags: ['verifier'] 218 bugid: ['2085'] 219 runner-options: ['verifier-failure', 'verifier-config'] 220 code-template: | 221 .function i32 main() { 222 %s 223 ldobj.64 v0, R.fi64 224 cases: 225 - values: 226 - movi v0, 0 227 bugid: ['1324', '1826'] 228 - values: 229 - movi v0, 1 230 - values: 231 - movi.64 v0, 0x00 232 bugid: ['1324', '1826'] 233 - values: 234 - movi.64 v0, 0xCAFECAFECAFECAFE 235 - values: 236 - fmovi.64 v0, 0.0 237 bugid: ['1324', '1826'] 238 - values: 239 - fmovi.64 v0, 6.62607015 240 - values: 241 - | 242 movi v1, 10 243 newarr v0, v1, R[] 244 bugid: ['1827'] 245 246 247 - file-name: "with_non_object_ref_j" 248 description: Check that verifier reports an error when the 1st operand is not a ref to an object (other than array) in PandaAssembly context. 249 isa: 250 verification: 251 - v1_object 252 header-template: ['PandaAssembly_header'] 253 check-type: exit-positive 254 tags: [verifier, pa-verifier] 255 bugid: ['3293'] 256 runner-options: ['verifier-failure', 'verifier-config', 'use-pa'] 257 code-template: | 258 .function i32 main() { 259 %s 260 ldobj.64 v0, R.fi64 261 cases: 262 - values: 263 - movi v0, 0 264 - values: 265 - movi v0, 1 266 - values: 267 - movi.64 v0, 0x00 268 - values: 269 - movi.64 v0, 0xCAFECAFECAFECAFE 270 - values: 271 - fmovi.64 v0, 0.0 272 - values: 273 - fmovi.64 v0, 6.62607015 274 - values: 275 - | 276 movi v1, 10 277 newarr v0, v1, R[] 278 279 280 - file-name: "with_static_field_id_p" 281 description: | 282 Check that verifier reports an error when the field doesn't resolve to a non-static valid object field in Panda context. 283 Incorrect usage cannot be compiled. 284 isa: 285 verification: 286 - field_id_non_static 287 header-template: [] 288 runner-options: ['compile-failure'] 289 bugid: ['1324', '1828', '1833', '2086'] 290 check-type: exit-positive 291 code-template: | 292 .record W { 293 i64 static_field <static> 294 } 295 .function void W.ctor(W a0) <ctor> { 296 return.void 297 } 298 .record random_record_name { 299 i64 random_field_name 300 } 301 .function void random_function_name() { 302 return.void 303 } 304 305 .function i32 main() { 306 initobj W.ctor 307 sta.obj v0 308 ldobj.64 v0, %s 309 cases: 310 - values: 311 - W.static_field 312 runner-options: ['verifier-failure', 'verifier-config'] 313 tags: ['verifier'] 314 - values: 315 - random_record_name 316 - values: 317 - random_function_name 318 - values: 319 - W.field_not_exists 320 - values: 321 - random_record_name.random_field_name 322 runner-options: ['verifier-failure', 'verifier-config'] 323 tags: ['verifier'] 324 bugid: ['3536'] 325 - values: 326 - 0 327 - values: 328 - -1.1 329 - values: 330 - "null" 331 - values: 332 - "\"abc\"" 333 334 335 - file-name: "with_static_field_id_j" 336 description: | 337 Check that verifier reports an error when the field doesn't resolve to a non-static valid object field in PandaAssembly context. 338 Incorrect usage cannot be compiled. 339 isa: 340 verification: 341 - field_id_non_static 342 header-template: [] 343 runner-options: ['compile-failure', 'use-pa'] 344 tags: [verifier, pa-verifier] 345 bugid: ['1324', '1828', '1833', '2086', '3293'] 346 check-type: exit-positive 347 code-template: | 348 .language PandaAssembly 349 .record W { 350 i64 static_field <static> 351 } 352 .function void W.ctor(W a0) <ctor> { 353 return.void 354 } 355 .record random_record_name { 356 i64 random_field_name 357 } 358 .function void random_function_name() { 359 return.void 360 } 361 362 .function i32 main() { 363 initobj W.ctor 364 sta.obj v0 365 ldobj.64 v0, %s 366 cases: 367 - values: 368 - W.static_field 369 tags: [verifier, pa-verifier] 370 runner-options: ['verifier-failure', 'verifier-config', 'use-pa'] 371 - values: 372 - random_record_name 373 - values: 374 - random_function_name 375 - values: 376 - W.field_not_exists 377 - values: 378 - random_record_name.random_field_name 379 tags: [verifier, pa-verifier] 380 runner-options: ['verifier-failure', 'verifier-config', 'use-pa'] 381 bugid: ['3536'] 382 - values: 383 - 0 384 - values: 385 - -1.1 386 - values: 387 - "null" 388 - values: 389 - "\"abc\"" 390 391 392 - file-name: "with_wrong_field_size_or_type_p" 393 description: Check that verifier reports an error when the field resolves to a field with size or type that is not corresponding to bytecode 394 isa: 395 verification: 396 - field_id_size 397 header-template: ['pandasm_header'] 398 check-type: exit-positive 399 tags: ['verifier'] 400 runner-options: ['verifier-failure', 'verifier-config'] 401 bugid: ['1834', '2088'] 402 code-template: | 403 404 .function i32 main() { 405 initobj R.ctor 406 sta.obj v0 407 ldobj.64 v0, %s 408 cases: 409 - values: 410 - R.fu1 411 - values: 412 - R.fu8 413 - values: 414 - R.fi8 415 - values: 416 - R.fu16 417 - values: 418 - R.fi16 419 - values: 420 - R.fu32 421 - values: 422 - R.fi32 423 - values: 424 - R.ff32 425 bugid: ['6094'] 426 - values: 427 - R.fObj 428 - values: 429 - R.fObjArray 430 - values: 431 - R.fi32Array 432 433 434 - file-name: "with_wrong_field_size_or_type_j" 435 description: Check that verifier reports an error when the field resolves to a field with size or type that is not corresponding to bytecode 436 isa: 437 verification: 438 - field_id_size 439 header-template: ['PandaAssembly_header'] 440 check-type: exit-positive 441 tags: [verifier, pa-verifier] 442 bugid: ['1834', '2088', '3293'] 443 runner-options: ['verifier-failure', 'verifier-config', 'use-pa'] 444 code-template: | 445 446 .function i32 main() { 447 initobj R.ctor 448 sta.obj v0 449 ldobj.64 v0, %s 450 cases: 451 - values: 452 - R.fu1 453 - values: 454 - R.fi8 455 - values: 456 - R.fu16 457 - values: 458 - R.fi16 459 - values: 460 - R.fi32 461 - values: 462 - R.ff32 463 bugid: ['6094'] 464 - values: 465 - R.fObj 466 - values: 467 - R.fObjArray 468 - values: 469 - R.fi32Array 470 471 472 - file-name: "with_correct_field_size_or_type_p" 473 description: Check that verifier does not report any error when the field has size or type that is corresponding to bytecode 474 isa: 475 verification: 476 - field_id_size 477 header-template: ['pandasm_header'] 478 check-type: exit-positive 479 tags: ['verifier'] 480 runner-options: ['verifier-only', 'verifier-config'] 481 code-template: | 482 483 .function i32 main() { 484 initobj R.ctor 485 sta.obj v0 486 ldobj.64 v0, %s 487 cases: 488 - values: 489 - R.fu64 490 - values: 491 - R.fi64 492 - values: 493 - R.ff64 494 495 496 - file-name: "op_v_8_id_16" 497 description: Check that compiler reports an error when the register number is incorrect 498 isa: 499 instructions: 500 - sig: ldobj.64 v:in:ref, field_id 501 acc: out:b64 502 format: [op_v_8_id_16] 503 header-template: ['pandasm_header'] 504 check-type: exit-positive 505 runner-options: ['compile-failure'] 506 code-template: | 507 508 .function i32 main() { 509 ldobj.64 %s, R.fi64 510 cases: 511 - values: ['v255'] 512 runner-options: ['compile-only'] 513 - values: ['v256'] 514 - values: ['v65535'] 515 - values: ['a0'] 516 - values: ['a1'] 517 - values: ['null'] 518 - values: ['1'] 519 - values: ['"0"'] 520 521 522 - file-name: "from_all_int_field_types" 523 description: Check that accumulator value is loaded from field into accumulator. More tests on ldobj.64 can be found in stobj.64 tests 524 isa: 525 instructions: 526 - sig: ldobj.64 v:in:ref, field_id 527 acc: out:b64 528 format: [op_v_8_id_16] 529 header-template: ['pandasm_header'] 530 check-type: exit-positive 531 tags: ['tsan'] 532 code-template: | 533 534 .function i32 main() { 535 initobj.short R.ctor 536 sta.obj v0 537 ldai.64 %s 538 stobj.64 v0, R.f%s 539 movi.64 v15, %s 540 ldobj.64 v0, R.f%s 541 %s v15 542 jeqz success 543 ldai 1 544 return 545 success: 546 cases: 547 # u64 548 - values: [0, 'u64', 0, 'u64', 'ucmp.64'] 549 - values: [0xffffffffffffffff, 'u64', 0xffffffffffffffff, 'u64', 'ucmp.64'] 550 - values: [0xa5a5a5a5a5a5a5a5, 'u64', 0xa5a5a5a5a5a5a5a5, 'u64', 'ucmp.64'] 551 # i64 552 - values: [0, 'i64', 0, 'i64', 'cmp.64'] 553 - values: [-1, 'i64', -1, 'i64', 'cmp.64'] 554 - values: [-6510615555426900571, 'i64', -6510615555426900571, 'i64', 'cmp.64'] 555 556 557 - file-name: "from_float_field_type" 558 description: Check that accumulator value is loaded from field into accumulator. More tests on ldobj.64 can be found in stobj.64 tests 559 isa: 560 instructions: 561 - sig: ldobj.64 v:in:ref, field_id 562 acc: out:b64 563 format: [op_v_8_id_16] 564 header-template: ['pandasm_header'] 565 tags: ['irtoc_ignore'] 566 bugid: ['3292'] 567 check-type: exit-positive 568 code-template: | 569 570 .function i32 main() { 571 initobj.short R.ctor 572 sta.obj v0 573 %s 574 stobj.64 v0, R.ff64 575 lda.null 576 %s 577 ldobj.64 v0, R.ff64 578 fcmpg.64 v15 579 %s 580 jeqz success 581 ldai 1 582 return 583 success: 584 cases: 585 # f64 586 - values: ['fldai.64 0.0', 'fmovi.64 v15, 0.0', ''] 587 - values: ['fldai.64 -6510615555426900571.0', 'fmovi.64 v15, -6510615555426900571.0', ''] 588 - values: ['fldai.64 0x7FFFFFFFFFFFFFFF', 'fmovi.64 v15, 0x7FFFFFFFFFFFFFFF', 'subi 1'] # NaN 589 - values: ['fldai.64 0x7ff0000000000000', 'fmovi.64 v15, 0x7ff0000000000000', ''] # + Inf 590 - values: ['fldai.64 0xfff0000000000000', 'fmovi.64 v15, 0xfff0000000000000', ''] # - Inf 591