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