1# Copyright (c) 2021 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: java_header 50 template: | 51 .language Java 52 53 .record java.lang.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 java.lang.Object fObj 74 java.lang.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:i32, 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:i32, 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-debug-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'] 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 162 163 - file-name: "with_non_object_ref" 164 description: Check that verifier reports an error when the 2nd operand is not a ref to an object (other than array) 165 isa: 166 verification: 167 - v2_object 168 header-template: ['pandasm_header'] 169 check-type: empty 170 tags: ['verifier'] 171 bugid: ['2085'] 172 runner-options: ['verifier-failure', 'verifier-debug-config'] 173 code-template: | 174 175 .function i32 main() { 176 %s 177 try_begin: 178 ldobj.v v1, v0, R.fu1 179 try_end: 180 ldai 0 181 return 182 .catchall try_begin, try_end, try_end 183 } 184 cases: 185 - values: 186 - movi v0, 0 187 tags: ['release', 'clang_release_sanitizer'] 188 bugid: ['1324', '1826'] 189 - values: 190 - movi v0, 1 191 - values: 192 - movi.64 v0, 0x00 193 tags: ['release', 'clang_release_sanitizer'] 194 bugid: ['1324', '1826'] 195 - values: 196 - movi.64 v0, 0xCAFECAFECAFECAFE 197 - values: 198 - fmovi.64 v0, 0.0 199 tags: ['release', 'clang_release_sanitizer'] 200 bugid: ['1324', '1826'] 201 - values: 202 - fmovi.64 v0, 6.62607015 203 - values: 204 - | 205 # 206 movi v1, 10 207 newarr v0, v1, R[] 208 bugid: ['1827'] 209 210 211 - file-name: "with_static_field_id" 212 description: Check that verifier reports an error if the field doesn't resolve to a non-static valid object field 213 isa: 214 verification: 215 - field_id_non_static 216 header-template: [] 217 check-type: exit-positive 218 code-template: | 219 .record W { 220 i32 static_field <static> 221 } 222 .function void W.ctor(W a0) <ctor> { 223 return.void 224 } 225 .record random_record_name { 226 i32 random_field_name 227 } 228 .function void random_function_name() { 229 return.void 230 } 231 232 .function i32 main() { 233 initobj W.ctor 234 sta.obj v0 235 ldobj.v v1, v0, %s 236 cases: 237 - values: 238 - W.static_field 239 tags: ['verifier'] 240 runner-options: ['verifier-failure', 'verifier-debug-config'] 241 bugid: ['1324', '1828', '2086'] 242 - values: 243 - random_record_name 244 runner-options: ['compile-failure'] 245 - values: 246 - random_function_name 247 runner-options: ['compile-failure'] 248 - values: 249 - W.field_not_exists 250 runner-options: ['compile-failure'] 251 - values: 252 - random_record_name.random_field_name 253 tags: ['verifier'] 254 runner-options: ['verifier-failure', 'verifier-debug-config'] 255 bugid: ['1833', '2086', '3536'] 256 - values: 257 - 0 258 runner-options: ['compile-failure'] 259 - values: 260 - -1.1 261 runner-options: ['compile-failure'] 262 - values: 263 - "null" 264 runner-options: ['compile-failure'] 265 - values: 266 - "\"abc\"" 267 runner-options: ['compile-failure'] 268 269 270 - file-name: "with_wrong_field_size_or_type" 271 description: Check that verifier reports an error when the field resolves to a field with size or type that is not corresponding to bytecode 272 isa: 273 verification: 274 - field_id_size 275 header-template: ['pandasm_header'] 276 check-type: exit-positive 277 tags: ['verifier'] 278 runner-options: ['verifier-failure', 'verifier-debug-config'] 279 bugid: ['1834', '2088'] 280 code-template: | 281 282 .function i32 main() { 283 initobj R.ctor 284 sta.obj v0 285 ldobj.v v1, v0, %s 286 cases: 287 - values: 288 - R.fi64 289 - values: 290 - R.fu64 291 - values: 292 - R.ff64 293 - values: 294 - R.ff32 295 - values: 296 - R.fObj 297 - values: 298 - R.fObjArray 299 - values: 300 - R.fi32Array 301 302 303 - file-name: "op_v1_4_v2_4_id_16" 304 description: Check that compiler reports an error when the register number is out of 4 bit size 305 isa: 306 instructions: 307 - sig: ldobj.v v1:out:i32, v2:in:ref, field_id 308 acc: none 309 format: [op_v1_4_v2_4_id_16] 310 header-template: ['pandasm_header'] 311 runner-options: ['compile-failure'] 312 check-type: exit-positive 313 code-template: | 314 315 .function i32 main() { 316 ldobj.v %s, R.fi32 317 cases: 318 - values: ['v15, v15'] 319 runner-options: ['compile-only'] 320 - values: ['v0, v16'] 321 - values: ['v16, v0'] 322 - values: ['v256, v0'] 323 - values: ['v1, v256'] 324 - values: ['v32567, v32567'] 325 - values: ['a0, v1'] 326 - values: ['v0, a1'] 327 - values: ['v0'] 328 - values: ['1'] 329 - values: ['"0"'] 330 331 332 - file-name: "from_all_field_types" 333 description: Check that field value is loaded into accumulator. More tests on ldobj.v can be found in stobj.v tests 334 isa: 335 description: > 336 For non-object variant, the size of the field is determined by the field_id, 337 most significant bits are sign or unsigned extended based on the field type to fit register size. 338 If field type is less than 32, then loaded value is sign or zero extended to i32 depending on field type. 339 header-template: ['pandasm_header'] 340 check-type: exit-positive 341 tags: ['tsan'] 342 code-template: | 343 344 .function i32 main() { 345 initobj.short R.ctor 346 sta.obj v0 347 ldai %s 348 stobj v0, R.f%s 349 lda.null 350 movi v15, %s 351 ldobj.v v1, v0, R.f%s 352 lda v1 353 %s v15 354 jeqz success 355 ldai 1 356 return 357 success: 358 cases: 359 # u1 360 - values: [0, 'u1', 0, 'u1', 'ucmp'] 361 - values: [1, 'u1', 1, 'u1', 'ucmp'] 362 # u8 363 - values: [0, 'u8', 0, 'u8', 'ucmp'] 364 - values: [0x000000ff, 'u8', 0x000000ff, 'u8', 'ucmp'] 365 - values: [0x000000a5, 'u8', 0x000000a5, 'u8', 'ucmp'] 366 # u16 367 - values: [0, 'u16', 0, 'u16', 'ucmp'] 368 - values: [0x0000ffff, 'u16', 0x0000ffff, 'u16', 'ucmp'] 369 - values: [0x0000a5a5, 'u16', 0x0000a5a5, 'u16', 'ucmp'] 370 # u32 371 - values: [0, 'u32', 0, 'u32', 'ucmp'] 372 - values: [0xffffffff, 'u32', 0xffffffff, 'u32', 'ucmp'] 373 - values: [0xa5a5a5a5, 'u32', 0xa5a5a5a5, 'u32', 'ucmp'] 374 375 376 - file-name: "from_all_field_types_int" 377 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. 378 isa: 379 description: > 380 For non-object variant, the size of the field is determined by the field_id, 381 most significant bits are sign or unsigned extended based on the field type to fit register size. 382 If field type is less than 32, then loaded value is sign or zero extended to i32 depending on field type. 383 header-template: ['pandasm_header'] 384 check-type: exit-positive 385 tags: ['tsan'] 386 code-template: | 387 388 .function i32 main() { 389 initobj.short R.ctor 390 sta.obj v0 391 ldai %s 392 stobj v0, R.f%s 393 lda.null 394 movi v15, %s 395 ldobj.v v1, v0, R.f%s 396 lda v1 397 jeq v15, success 398 ldai 1 399 return 400 success: 401 cases: 402 # i8 403 - values: [0, 'i8', 0, 'i8'] 404 - values: [0x000000ff, 'i8', 0xffffffff, 'i8'] 405 - values: [0x000000a5, 'i8', 0xffffffa5, 'i8'] 406 - values: [0x0000005a, 'i8', 0x0000005a, 'i8'] 407 # i16 408 - values: [0, 'i16', 0, 'i16'] 409 - values: [0x0000ffff, 'i16', 0xffffffff, 'i16'] 410 - values: [0x0000a5a5, 'i16', 0xffffa5a5, 'i16'] 411 - values: [0x00005a5a, 'i16', 0x00005a5a, 'i16'] 412 # i32 413 - values: [0, 'i32', 0, 'i32'] 414 - values: [0xffffffff, 'i32', 0xffffffff, 'i32'] 415 - values: [0xa5a5a5a5, 'i32', 0xa5a5a5a5, 'i32'] 416 - values: [0x5a5a5a5a, 'i32', 0x5a5a5a5a, 'i32'] 417 418 - file-name: "from_float_field_type" 419 description: Check that accumulator value is loaded from field into accumulator. More tests on ldobj.v can be found in stobj.v tests 420 isa: 421 instructions: 422 - sig: ldobj.v v1:out:b32, v2:in:ref, field_id 423 acc: none 424 format: [op_v1_4_v2_4_id_16] 425 header-template: ['pandasm_header'] 426 bugid: ['3292'] 427 check-type: exit-positive 428 code-template: | 429 430 .function i32 main() { 431 initobj.short R.ctor 432 sta.obj v0 433 %s 434 stobj v0, R.ff32 435 lda.null 436 %s 437 ldobj.v v1, v0, R.ff32 438 lda v1 439 fcmpg v15 440 %s 441 jeqz success 442 ldai 1 443 return 444 success: 445 cases: 446 # f32 447 - values: ['fldai 0.0', 'fmovi v15, 0.0', ''] 448 - values: ['fldai -6510615.0', 'fmovi v15, -6510615.0', ''] 449 - values: ['fldai 0x7FFFFFFF', 'fmovi v15, 0x7FFFFFFF', 'subi 1'] # NaN 450 - values: ['fldai 0x7f800000', 'fmovi v15, 0x7f800000', ''] # + Inf 451 - values: ['fldai 0xff800000', 'fmovi v15, 0xff800000', ''] # - Inf 452