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: 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 <static> 28 u8 fu8 <static> 29 i8 fi8 <static> 30 u16 fu16 <static> 31 i16 fi16 <static> 32 u32 fu32 <static> 33 i32 fi32 <static> 34 u64 fu64 <static> 35 i64 fi64 <static> 36 f32 ff32 <static> 37 f64 ff64 <static> 38 # objects: 39 i32[] fi32Array <static> 40 Q fQ <static> 41 Q[] fQArray <static> 42 R fR <static> 43 R[] fRArray <static> 44 panda.Object fObj <static> 45 panda.Object fObj2 <static> 46 panda.Object[] fObjArray <static> 47 } 48 .function void R.ctor(R a0) <ctor> { 49 return.void 50 } 51 52 - name: PandaAssembly_header 53 template: | 54 .language PandaAssembly 55 56 .record panda.Object <external> 57 .function void panda.Object.ctor(panda.Object a0) <external, ctor> 58 59 .record I <panda.interface> {} 60 61 .record Q <panda.implements=I> {} 62 .function void Q.ctor(Q a0) <ctor> { 63 return.void 64 } 65 66 .record R <panda.extends=Q> { 67 u1 fu1 <static> 68 i8 fi8 <static> 69 u16 fu16 <static> 70 i16 fi16 <static> 71 i32 fi32 <static> 72 i64 fi64 <static> 73 f32 ff32 <static> 74 f64 ff64 <static> 75 # objects 76 i32[] fi32Array <static> 77 Q fQ <static> 78 Q[] fQArray <static> 79 R fR <static> 80 R[] fRArray <static> 81 I fI <static> 82 I[] fIArray <static> 83 panda.Object fObj <static> 84 panda.Object fObj2 <static> 85 panda.Object[] fObjArray <static> 86 } 87 .function void R.ctor(R a0) <ctor> { 88 return.void 89 } 90 91tests: 92 - file-name: "ldstatic.obj" 93 isa: 94 title: Get static field 95 description: > 96 Get static field value by field_id and put it into accumulator. 97 instructions: 98 - sig: ldstatic.obj field_id 99 acc: out:ref 100 format: [op_id_16] 101 commands: 102 103 - file-name: "with_non_static_field_id" 104 description: Check that verifier reports error when the field doesn't resolve to a static valid field 105 isa: 106 verification: 107 - field_id_static 108 header-template: [] 109 check-type: exit-positive 110 code-template: | 111 .record W { 112 u1 fu1 113 i8 fi8 114 u16 fu16 115 i16 fi16 116 i32 fi32 117 i64 fi64 118 f32 ff32 119 f64 ff64 120 W fW 121 i32[] fi32Array 122 W[] fWArray 123 } 124 .function void W.object_function(W a0) { 125 return.void 126 } 127 .function void static_function() { 128 return.void 129 } 130 131 .function i32 main() { 132 ldstatic.obj %s 133 cases: 134 - values: 135 - W.fu1 136 tags: [verifier] 137 runner-options: ['verifier-failure', 'verifier-config'] 138 bugid: ['1324', '1828'] 139 - values: 140 - W.fi8 141 tags: [verifier] 142 runner-options: ['verifier-failure', 'verifier-config'] 143 bugid: ['1324', '1828'] 144 - values: 145 - W.fu16 146 tags: [verifier] 147 runner-options: ['verifier-failure', 'verifier-config'] 148 bugid: ['1324', '1828'] 149 - values: 150 - W.fi16 151 tags: [verifier] 152 runner-options: ['verifier-failure', 'verifier-config'] 153 bugid: ['1324', '1828'] 154 - values: 155 - W.fi32 156 tags: [verifier] 157 runner-options: ['verifier-failure', 'verifier-config'] 158 bugid: ['1324', '1828'] 159 - values: 160 - W.fi64 161 tags: [verifier] 162 runner-options: ['verifier-failure', 'verifier-config'] 163 bugid: ['1324', '1828'] 164 - values: 165 - W.ff32 166 tags: [verifier] 167 runner-options: ['verifier-failure', 'verifier-config'] 168 bugid: ['1324', '1828'] 169 - values: 170 - W.ff64 171 tags: [verifier] 172 runner-options: ['verifier-failure', 'verifier-config'] 173 bugid: ['1324', '1828'] 174 - values: 175 - W.fW 176 tags: [verifier] 177 runner-options: ['verifier-failure', 'verifier-config'] 178 bugid: ['1324', '1828'] 179 - values: 180 - W.fi32Array 181 tags: [verifier] 182 runner-options: ['verifier-failure', 'verifier-config'] 183 bugid: ['1324', '1828'] 184 - values: 185 - W.fWArray 186 tags: [verifier] 187 runner-options: ['verifier-failure', 'verifier-config'] 188 bugid: ['1324', '1828'] 189 - values: 190 - W 191 runner-options: [compile-failure] 192 - values: 193 - W.object_function 194 runner-options: [compile-failure] 195 - values: 196 - static_function 197 runner-options: [compile-failure] 198 - values: 199 - unknown_function 200 runner-options: [compile-failure] 201 - values: 202 - 0 203 runner-options: [compile-failure] 204 - values: 205 - -1.1 206 runner-options: [compile-failure] 207 - values: 208 - "null" 209 runner-options: [compile-failure] 210 - values: 211 - "\"abc\"" 212 runner-options: [compile-failure] 213 214 215 - file-name: "with_wrong_field_size_or_type_p" 216 description: Check that verifier reports an error when the field resolves to a field with size or type that is not corresponding to bytecode in PandaAssembly context. 217 isa: 218 verification: 219 - field_id_size 220 header-template: [pandasm_header] 221 check-type: exit-positive 222 tags: [verifier] 223 runner-options: ['verifier-failure', 'verifier-config'] 224 bugid: ['1834', '2088'] 225 code-template: | 226 227 .function i32 main() { 228 ldstatic.obj %s 229 cases: 230 - values: 231 - R.fu1 232 - values: 233 - R.fu8 234 - values: 235 - R.fi8 236 - values: 237 - R.fu16 238 - values: 239 - R.fi16 240 - values: 241 - R.fu32 242 - values: 243 - R.fi32 244 - values: 245 - R.fu64 246 - values: 247 - R.fi64 248 - values: 249 - R.ff32 250 - values: 251 - R.ff64 252 253 254 - file-name: "with_wrong_field_size_or_type_j" 255 description: Check that verifier reports an error when the field resolves to a field with size or type that is not corresponding to bytecode in PandaAssembly context. 256 isa: 257 verification: 258 - field_id_size 259 header-template: [PandaAssembly_header] 260 check-type: exit-positive 261 tags: [verifier, pa-verifier] 262 runner-options: [verifier-failure, use-pa, verifier-config] 263 bugid: ["5271"] 264 code-template: | 265 266 .function i32 main() { 267 ldstatic.obj %s 268 cases: 269 - values: 270 - R.fu1 271 - values: 272 - R.fi8 273 - values: 274 - R.fu16 275 - values: 276 - R.fi16 277 - values: 278 - R.fi32 279 - values: 280 - R.fi64 281 - values: 282 - R.ff32 283 - values: 284 - R.ff64 285 286 287 - file-name: "from_all_field_types_pa" 288 description: Check that accumulator value is loaded from field into accumulator in PandaAssembly context. More tests on ldstatic.obj can be found in ststatic.obj tests 289 isa: 290 description: Get static field value by field_id and put it into accumulator. 291 header-template: [pandasm_header] 292 check-type: exit-positive 293 tags: ['tsan'] 294 code-template: | 295 296 .function i32 main() { 297 # store null into Q type field 298 lda.null 299 sta.obj v3 300 ststatic.obj R.fQ 301 # store null into Q[] type field 302 lda.null 303 sta.obj v4 304 ststatic.obj R.fQArray 305 # store R object into R type field 306 initobj R.ctor 307 sta.obj v5 308 ststatic.obj R.fR 309 # store R[] into R[] type field 310 movi v1, 10 311 newarr v6, v1, R[] 312 lda.obj v6 313 ststatic.obj R.fRArray 314 # store R object into panda.Object type field 315 initobj R.ctor 316 sta.obj v7 317 ststatic.obj R.fObj 318 # store R[] into panda.Object type field 319 movi v1, 10 320 newarr v8, v1, R[] 321 lda.obj v8 322 ststatic.obj R.fObj2 323 # store R[] into panda.Object[] type field 324 movi v1, 10 325 newarr v9, v1, R[] 326 lda.obj v9 327 ststatic.obj R.fObjArray 328 label0: 329 # load null from Q type field 330 ldstatic.obj R.fQ 331 jeq.obj v3, label1 332 ldai 1 333 return 334 label1: 335 # load null from Q[] type field 336 ldstatic.obj R.fQArray 337 jeq.obj v4, label2 338 ldai 2 339 return 340 label2: 341 # load R object from R type field 342 ldstatic.obj R.fR 343 jeq.obj v5, label3 344 ldai 3 345 return 346 label3: 347 # load R[] from R[] type field 348 ldstatic.obj R.fRArray 349 jeq.obj v6, label4 350 ldai 4 351 return 352 label4: 353 # load R object from panda.Object type field 354 ldstatic.obj R.fObj 355 jeq.obj v7, label5 356 ldai 5 357 return 358 label5: 359 # load R[] from panda.Object type field 360 ldstatic.obj R.fObj2 361 jeq.obj v8, label6 362 ldai 6 363 return 364 label6: 365 # load R[] from panda.Object[] type field 366 ldstatic.obj R.fObjArray 367 jeq.obj v9, success 368 ldai 7 369 return 370 success: 371 372 - file-name: "from_all_field_types_j" 373 description: Check that accumulator value is loaded from field into accumulator in PandaAssembly context. More tests on ldstatic.obj can be found in ststatic.obj tests 374 isa: 375 description: Get static field value by field_id and put it into accumulator. 376 header-template: [PandaAssembly_header] 377 runner-options: [use-pa] 378 check-type: exit-positive 379 code-template: | 380 381 .function i32 main() { 382 # store subsclass R into Q type field 383 initobj R.ctor 384 sta.obj v3 385 ststatic.obj R.fQ 386 # store subsclass R into interface type field 387 initobj R.ctor 388 sta.obj v4 389 ststatic.obj R.fI 390 # store subsclass R into base type field 391 initobj R.ctor 392 sta.obj v5 393 ststatic.obj R.fObj 394 # store subclass R[] into Q[] type field 395 movi v1, 10 396 newarr v6, v1, R[] 397 lda.obj v6 398 ststatic.obj R.fQArray 399 # store subclass R[] into interface [] type field 400 movi v1, 10 401 newarr v7, v1, R[] 402 lda.obj v7 403 ststatic.obj R.fIArray 404 # store subclass R[] into base type [] field 405 movi v1, 10 406 newarr v8, v1, R[] 407 lda.obj v8 408 ststatic.obj R.fObjArray 409 # store subclass R[] into base type field 410 movi v1, 10 411 newarr v9, v1, R[] 412 lda.obj v9 413 ststatic.obj R.fObj2 414 label0: 415 # load R from Q type field 416 ldstatic.obj R.fQ 417 jeq.obj v3, label1 418 ldai 1 419 return 420 label1: 421 # load R from interface type field 422 ldstatic.obj R.fI 423 jeq.obj v4, label2 424 ldai 2 425 return 426 label2: 427 # load R from base type field 428 ldstatic.obj R.fObj 429 jeq.obj v5, label3 430 ldai 3 431 return 432 label3: 433 # load R[] from Q[] type field 434 ldstatic.obj R.fQArray 435 jeq.obj v6, label4 436 ldai 4 437 return 438 label4: 439 # load R[] from interface[] type field 440 ldstatic.obj R.fIArray 441 jeq.obj v7, label5 442 ldai 5 443 return 444 label5: 445 # load R[] from base type [] field 446 ldstatic.obj R.fObjArray 447 jeq.obj v8, label6 448 ldai 6 449 return 450 label6: 451 # load R[] from base type field 452 ldstatic.obj R.fObj2 453 jeq.obj v9, success 454 ldai 7 455 return 456 success: 457 458 - file-name: "x_init_p" 459 description: Check that ExceptionInInitializerError is thrown if an unexpected exception occurs in static initializer. 460 isa: 461 exceptions: 462 - x_init 463 header-template: [] 464 check-type: empty 465 tags: ['tsan', 'irtoc_ignore'] 466 bugid: ['5330'] 467 code-template: | 468 469 .language PandaAssembly 470 471 .record panda.ExceptionInInitializerError <external> 472 .record panda.NullPointerException <external> 473 .record E1 {} 474 .record R { 475 E1 fObj <static> 476 } 477 478 .function void R.func() <cctor> { 479 %s 480 return.void 481 } 482 483 .function i32 main() { 484 begin: 485 ldstatic.obj R.fObj 486 ldai 2 487 return 488 end: 489 catch: 490 ldai 0 491 return 492 catch_all: 493 ldai 1 494 return 495 .catch panda.ExceptionInInitializerError, begin, end, catch 496 .catchall begin, end, catch_all 497 } 498 cases: 499 - values: 500 - | 501 # 502 newobj v0, E1 503 throw v0 504 - values: 505 - | 506 # 507 newobj v0, panda.NullPointerException 508 throw v0 509 - values: 510 - | 511 # 512 movi v1, 0 513 ldai 1 514 div2 v1 # divide by zero 515 - values: 516 - | 517 # 518 movi v1, 10 519 newarr v1, v1, i32[] 520 ldai 10 521 ldarr v1 # get ArrayIndexOutOfBoundsException 522 523 - file-name: "x_init_j" 524 description: Check that ExceptionInInitializerError is thrown if an unexpected exception occurs in static initializer. 525 isa: 526 exceptions: 527 - x_init 528 header-template: [] 529 check-type: empty 530 tags: ['tsan', 'irtoc_ignore'] 531 runner-options: ['use-pa'] 532 code-template: | 533 534 .language PandaAssembly 535 536 .record panda.ExceptionInInitializerError <external> 537 .record panda.NullPointerException <external> 538 .record E1 {} 539 .record R { 540 E1 fObj <static> 541 } 542 .record Q <panda.extends=R> { 543 E1 fObj <static> 544 } 545 .function void R.func() <cctor> { 546 %s 547 return.void 548 } 549 550 .function i32 main() { 551 begin: 552 ldstatic.obj Q.fObj 553 ldai 2 554 return 555 end: 556 catch: 557 ldai 0 558 return 559 catch_all: 560 ldai 1 561 return 562 .catch panda.ExceptionInInitializerError, begin, end, catch 563 .catchall begin, end, catch_all 564 } 565 cases: 566 - values: 567 - | 568 # 569 newobj v0, E1 570 throw v0 571 - values: 572 - | 573 # 574 newobj v0, panda.NullPointerException 575 throw v0 576 - values: 577 - | 578 # 579 movi v1, 0 580 ldai 1 581 div2 v1 # divide by zero 582 - values: 583 - | 584 # 585 movi v1, 10 586 newarr v1, v1, i32[] 587 ldai 10 588 ldarr v1 # get ArrayIndexOutOfBoundsException 589 590