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