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 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 panda.Object fObj 43 panda.Object[] fObjArray 44 } 45 .function void R.ctor(R a0) <ctor> { 46 return.void 47 } 48 49tests: 50 - file-name: "stobj" 51 isa: 52 title: Store accumulator content into object field 53 description: > 54 Store accumulator content into object field by field_id. For non-object variant the size of actually stored 55 value is determined by field_id, other accumulator bits are discarded. 56 instructions: 57 - sig: stobj v:in:ref, field_id 58 acc: in:i32 59 format: [op_v_8_id_16] 60 commands: 61 62 - file-name: "check_if_regs_initialized" 63 description: Check that verifier reports error if source registers are not initialized 64 isa: 65 description: Store accumulator content into object field by field_id. 66 header-template: ['pandasm_header'] 67 check-type: exit-positive 68 tags: ['verifier'] 69 bugid: ['1324'] 70 runner-options: ['verifier-failure', 'verifier-config'] 71 code-template: | 72 73 %s 74 75 .function i32 main() { 76 initobj R.ctor 77 sta.obj v0 78 movi v1, 1 79 call.short check, %s 80 cases: 81 - values: 82 - | 83 # acc (value) not initialized in the frame 84 .function void check(R a0) { 85 stobj a0, R.fi32 86 return.void 87 } 88 - v0 89 - values: 90 - | 91 # v0 (object) not initialized in the frame 92 .function void check(i32 a0) { 93 lda a0 94 stobj v0, R.fi32 95 return.void 96 } 97 - v1 98 bugid: ['1324'] 99 100 101 - file-name: "with_null_ref" 102 description: Check that NullPointerException is thrown if object ref is null 103 isa: 104 exceptions: 105 - x_null 106 header-template: ['pandasm_header'] 107 check-type: empty 108 tags: ['irtoc_ignore'] 109 bugid: ['3047'] 110 code-template: | 111 .record panda.NullPointerException <external> 112 113 .function R get_null() { 114 lda.null 115 return.obj 116 } 117 118 .function i32 main() { 119 call.short get_null 120 sta.obj v0 121 %s 122 try_begin: 123 stobj v0, %s 124 ldai 1 125 return 126 try_end: 127 ldai 0 128 return 129 .catch panda.NullPointerException, try_begin, try_end, try_end 130 } 131 cases: 132 - values: 133 - ldai 1 134 - R.fu1 135 - values: 136 - ldai 1 137 - R.fu8 138 - values: 139 - ldai 1 140 - R.fi8 141 - values: 142 - ldai 1 143 - R.fu16 144 - values: 145 - ldai 1 146 - R.fi16 147 - values: 148 - ldai 1 149 - R.fu32 150 - values: 151 - ldai 1 152 - R.fi32 153 - values: 154 - fldai 1.1 155 - R.ff32 156 bugid: ['1882'] 157 158 159 - file-name: "with_non_object_ref" 160 description: Check that verifier reports error when the 1st operand is not a ref to an object (other than array) 161 isa: 162 verification: 163 - v1_object 164 header-template: ['pandasm_header'] 165 check-type: empty 166 tags: ['verifier'] 167 bugid: ['1324', '1826', '1827'] 168 runner-options: ['verifier-failure', 'verifier-config'] 169 code-template: | 170 171 .function i32 main() { 172 %s 173 ldai 1 174 try_begin: 175 stobj v0, R.fi32 176 try_end: 177 ldai 0 178 return 179 .catchall try_begin, try_end, try_end 180 } 181 cases: 182 - values: 183 - movi v0, 0 184 - values: 185 - movi v0, 1 186 - values: 187 - movi.64 v0, 0x00 188 - values: 189 - movi.64 v0, 0xCAFECAFECAFECAFE 190 - values: 191 - fmovi.64 v0, 0.0 192 - values: 193 - fmovi.64 v0, 6.62607015 194 - values: 195 - | 196 movi v1, 10 197 newarr v0, v1, R[] 198 199 200 - file-name: "with_static_field_id" 201 description: Check that verifier reports error if the field doesn't resolve to a non-static valid object field 202 isa: 203 verification: 204 - field_id_non_static 205 header-template: [] 206 check-type: exit-positive 207 bugid: ['1324', '1828', '1833'] 208 runner-options: ['verifier-failure', 'verifier-config'] 209 tags: ['verifier'] 210 code-template: | 211 .record W { 212 i32 static_field <static> 213 } 214 .function void W.ctor(W a0) <ctor> { 215 return.void 216 } 217 .record random_record_name { 218 i32 random_field_name 219 } 220 .function void random_function_name() { 221 return.void 222 } 223 224 .function i32 main() { 225 initobj W.ctor 226 sta.obj v0 227 ldai 1 228 stobj v0, %s 229 cases: 230 - values: 231 - W.static_field 232 - values: 233 - random_record_name 234 runner-options: ['compile-failure'] 235 - values: 236 - random_function_name 237 runner-options: ['compile-failure'] 238 - values: 239 - W.field_not_exists 240 runner-options: ['compile-failure'] 241 - values: 242 - random_record_name.random_field_name 243 bugid: ['3536'] 244 - values: 245 - 0 246 runner-options: ['compile-failure'] 247 - values: 248 - -1.1 249 runner-options: ['compile-failure'] 250 - values: 251 - "null" 252 runner-options: ['compile-failure'] 253 - values: 254 - "\"abc\"" 255 runner-options: ['compile-failure'] 256 257 258 - file-name: "with_wrong_field_size" 259 description: Check that verifier reports error when the field resolves to a field with size that is not corresponding to bytecode 260 isa: 261 verification: 262 - field_id_size 263 header-template: ['pandasm_header'] 264 check-type: exit-positive 265 tags: ['verifier'] 266 runner-options: ['verifier-failure', 'verifier-config'] 267 bugid: ['1834'] 268 code-template: | 269 .function i32 main() { 270 initobj R.ctor 271 sta.obj v0 272 %s 273 stobj v0, %s 274 cases: 275 - values: 276 - ldai 0 277 - R.fi64 278 - values: 279 - ldai 0 280 - R.fu64 281 - values: 282 - fldai 0.0 283 - R.ff64 284 - values: 285 - ldai 1 286 - R.fObj 287 - values: 288 - ldai 2 289 - R.fObjArray 290 - values: 291 - ldai 3 292 - R.fi32Array 293 294 295 - file-name: "with_correct_field_size_or_type" 296 description: Check that verifier does not report any error when the field has size or type corresponding to bytecode 297 isa: 298 verification: 299 - field_id_size 300 header-template: ['pandasm_header'] 301 check-type: exit-positive 302 tags: ['verifier'] 303 runner-options: ['verifier-only', 'verifier-config'] 304 code-template: | 305 .function i32 main() { 306 initobj R.ctor 307 sta.obj v0 308 %s 309 stobj v0, %s 310 cases: 311 - values: 312 - ldai 0 313 - R.fu1 314 - values: 315 - ldai 1 316 - R.fu8 317 - values: 318 - ldai 2 319 - R.fi8 320 - values: 321 - ldai 3 322 - R.fu16 323 - values: 324 - ldai 4 325 - R.fi16 326 - values: 327 - ldai 5 328 - R.fu32 329 - values: 330 - ldai 6 331 - R.fi32 332 - values: 333 - fldai 0.0 334 - R.ff32 335 336 337 - file-name: "with_wrong_acc_type" 338 description: Check that verifier reports error when the accumulator contains a value of type not corresponding to the bytecode 339 isa: 340 verification: 341 - acc_type 342 header-template: ['pandasm_header'] 343 check-type: exit-positive 344 tags: ['verifier'] 345 runner-options: ['verifier-failure', 'verifier-config'] 346 code-template: | 347 .function i32 main() { 348 initobj R.ctor 349 sta.obj v0 350 %s 351 stobj v0, %s 352 cases: 353 - values: 354 - ldai.64 0xF000F000F000F000 355 - R.fu1 356 bugid: ['4166'] 357 - values: 358 - ldai.64 0 359 - R.fi8 360 bugid: ['4166'] 361 - values: 362 - ldai.64 0xCAFECAFECAFECAFE 363 - R.fu8 364 bugid: ['4166'] 365 - values: 366 - ldai.64 0 367 - R.fi16 368 bugid: ['4166'] 369 - values: 370 - ldai.64 0x5A5A5A5A5A5A5A5A 371 - R.fi32 372 bugid: ['1834'] 373 - values: 374 - ldai.64 1234567890 375 - R.fu32 376 bugid: ['1834'] 377 - values: 378 - fldai.64 0x7FFFFFFFFFFFFFFF 379 - R.fu1 380 - values: 381 - fldai.64 0.0 382 - R.fu8 383 - values: 384 - fldai.64 -0.0 385 - R.fi8 386 - values: 387 - fldai.64 1.0 388 - R.fu16 389 - values: 390 - fldai.64 3.0 391 - R.fi16 392 - values: 393 - fldai.64 0.123456 394 - R.fu32 395 - values: 396 - fldai.64 123456.0 397 - R.fi32 398 - values: 399 - ldai.64 0 400 - R.ff32 401 - values: 402 - fldai.64 7890.0 403 - R.ff32 404 bugid: ['4166'] 405 - values: 406 - lda.null 407 - R.fu32 408 - values: 409 - initobj Q.ctor 410 - R.fi32 411 - values: 412 - | 413 movi v1, 10 414 newarr v1, v1, i32[] 415 lda.obj v1 416 - R.ff32 417 418 419 - file-name: "op_v_8_id_16" 420 description: Check that compiler reports error when the register number is out of 8 bit size 421 isa: 422 instructions: 423 - sig: stobj v:in:ref, field_id 424 acc: in:i32 425 format: [op_v_8_id_16] 426 header-template: ['pandasm_header'] 427 check-type: exit-positive 428 code-template: | 429 430 .function i32 main() { 431 stobj %s, R.fi32 432 cases: 433 - values: ['v255'] 434 runner-options: ['compile-only'] 435 - values: ['v256'] 436 runner-options: ['compile-failure'] 437 - values: ['v65535'] 438 runner-options: ['compile-failure'] 439 440 441 - file-name: "into_all_field_types" 442 description: Check that accumulator value is stored in field 443 isa: 444 description: If field type size is less than 32, accumulator content will be truncated to storage size before storing. 445 header-template: ['pandasm_header'] 446 check-type: exit-positive 447 tags: ['tsan', 'irtoc_ignore'] 448 code-template: | 449 450 .function i32 main() { 451 initobj R.ctor 452 sta.obj v0 453 %s 454 stobj v0, R.%s 455 lda.null 456 ldobj v0, R.%s 457 %s v1, %s 458 %s v1 459 %s 460 jeqz success 461 ldai 1 462 return 463 success: 464 cases: 465 # u1 466 - values: ['ldai 0x00000000', 'fu1', 'fu1', 'movi', 0, 'ucmp', ''] 467 - values: ['ldai 0xffffffff', 'fu1', 'fu1', 'movi', 1, 'ucmp', ''] 468 bugid: ['1848'] 469 ignore: true 470 - values: ['ldai 0x00000001', 'fu1', 'fu1', 'movi', 1, 'ucmp', ''] 471 - values: ['ldai 0xfffffffe', 'fu1', 'fu1', 'movi', 0, 'ucmp', ''] 472 bugid: ['1848'] 473 ignore: true 474 - values: ['ldai 0x11111111', 'fu1', 'fu1', 'movi', 1, 'ucmp', ''] 475 bugid: ['1848'] 476 ignore: true 477 - values: ['ldai 0x88888888', 'fu1', 'fu1', 'movi', 0, 'ucmp', ''] 478 bugid: ['1848'] 479 ignore: true 480 # u8 481 - values: ['ldai 0x00000000', 'fu8', 'fu8', 'movi', 0, 'ucmp', ''] 482 - values: ['ldai 0xffffffff', 'fu8', 'fu8', 'movi', 255, 'ucmp', ''] 483 - values: ['ldai 0x000000ff', 'fu8', 'fu8', 'movi', 255, 'ucmp', ''] 484 - values: ['ldai 0xffffff00', 'fu8', 'fu8', 'movi', 0, 'ucmp', ''] 485 - values: ['ldai 0x11111111', 'fu8', 'fu8', 'movi', 17, 'ucmp', ''] 486 - values: ['ldai 0x88888888', 'fu8', 'fu8', 'movi', 136, 'ucmp', ''] 487 # u16 488 - values: ['ldai 0x00000000', 'fu16', 'fu16', 'movi', 0, 'ucmp', ''] 489 - values: ['ldai 0xffffffff', 'fu16', 'fu16', 'movi', 65535, 'ucmp', ''] 490 - values: ['ldai 0x0000ffff', 'fu16', 'fu16', 'movi', 65535, 'ucmp', ''] 491 - values: ['ldai 0xffff0000', 'fu16', 'fu16', 'movi', 0, 'ucmp', ''] 492 - values: ['ldai 0x11111111', 'fu16', 'fu16', 'movi', 4369, 'ucmp', ''] 493 - values: ['ldai 0x88888888', 'fu16', 'fu16', 'movi', 34952, 'ucmp', ''] 494 # u32 495 - values: ['ldai 0x00000000', 'fu32', 'fu32', 'movi', 0, 'ucmp', ''] 496 - values: ['ldai 0xffffffff', 'fu32', 'fu32', 'movi', 4294967295, 'ucmp', ''] 497 - values: ['ldai 0x11111111', 'fu32', 'fu32', 'movi', 286331153, 'ucmp', ''] 498 - values: ['ldai 0x88888888', 'fu32', 'fu32', 'movi', 2290649224, 'ucmp', ''] 499 # f32 500 - values: ['fldai 0.0', 'ff32', 'ff32', 'fmovi', 0.0, 'fcmpg', ''] 501 bugid: ['3292'] 502 - values: ['fldai -6510615.0', 'ff32', 'ff32', 'fmovi', -6510615.0, 'fcmpg', ''] 503 bugid: ['3292'] 504 - values: ['fldai 0x7fffffff', 'ff32', 'ff32', 'fmovi', 0.0, 'fcmpg', 'subi 1'] 505 bugid: ['3292'] 506 - values: ['fldai 0x7f800000', 'ff32', 'ff32', 'fmovi', '0x7f800000', 'fcmpg', ''] 507 bugid: ['3292'] 508 - values: ['fldai 0xff800000', 'ff32', 'ff32', 'fmovi', '0xff800000', 'fcmpg', ''] 509 bugid: ['3292'] 510 511 - file-name: "into_all_field_types_int" 512 description: Version for integer types 513 isa: 514 description: If field type size is less than 32, accumulator content will be truncated to storage size before storing. 515 header-template: ['pandasm_header'] 516 check-type: exit-positive 517 tags: ['tsan', 'irtoc_ignore'] 518 code-template: | 519 520 .function i32 main() { 521 initobj R.ctor 522 sta.obj v0 523 %s 524 stobj v0, R.%s 525 lda.null 526 ldobj v0, R.%s 527 movi v1, %s 528 jeq v1, success 529 ldai 1 530 return 531 success: 532 cases: 533 # i8 534 - values: ['ldai 0x00000000', 'fi8', 'fi8', 0] 535 - values: ['ldai 0xffffffff', 'fi8', 'fi8', -1] 536 - values: ['ldai 0x000000ff', 'fi8', 'fi8', -1] 537 - values: ['ldai 0xffffff00', 'fi8', 'fi8', 0] 538 - values: ['ldai 0x11111111', 'fi8', 'fi8', 17] 539 - values: ['ldai 0x88888888', 'fi8', 'fi8', -120] 540 # i16 541 - values: ['ldai 0x00000000', 'fi16', 'fi16', 0] 542 - values: ['ldai 0xffffffff', 'fi16', 'fi16', -1] 543 - values: ['ldai 0x0000ffff', 'fi16', 'fi16', -1] 544 - values: ['ldai 0xffff0000', 'fi16', 'fi16', 0] 545 - values: ['ldai 0x11111111', 'fi16', 'fi16', 4369] 546 - values: ['ldai 0x88888888', 'fi16', 'fi16', -30584] 547 # i32 548 - values: ['ldai 0x00000000', 'fi32', 'fi32', 0] 549 - values: ['ldai 0xffffffff', 'fi32', 'fi32', -1] 550 - values: ['ldai 0x11111111', 'fi32', 'fi32', 286331153] 551 - values: ['ldai 0x88888888', 'fi32', 'fi32', -2004318072] 552 553