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 panda.Object fObj <static> 43 panda.Object[] fObjArray <static> 44 } 45 46tests: 47 - file-name: "ststatic.64" 48 isa: 49 title: Store to static field 50 description: > 51 Store accumulator content into static field by field_id. For non-object variant the size of actually stored 52 value is determined by field_id, other accumulator bits are discarded. 53 instructions: 54 - sig: ststatic.64 field_id 55 acc: in:b64 56 format: [op_id_16] 57 commands: 58 59 - file-name: "check_if_acc_initialized" 60 description: Check that verifier reports an error if accumulator is not initialized 61 isa: 62 description: Store accumulator content into static field by field_id. 63 header-template: ['pandasm_header'] 64 check-type: exit-positive 65 tags: ['verifier'] 66 bugid: ['1324'] 67 runner-options: ['verifier-failure', 'verifier-config'] 68 code-template: | 69 70 .function i32 main() { 71 # acc (value) not initialized, verifier error expected 72 ststatic.64 R.fi64 73 74 75 - file-name: "with_non_static_field_id" 76 description: Check that verifier reports an error when the field_id doesn't resolve to a static valid field 77 isa: 78 verification: 79 - field_id_static 80 header-template: [] 81 check-type: exit-positive 82 code-template: | 83 .record W { 84 u1 fu1 85 i8 fi8 86 u16 fu16 87 i16 fi16 88 i32 fi32 89 i64 fi64 90 f32 ff32 91 f64 ff64 92 W fW 93 i32[] fi32Array 94 W[] fWArray 95 } 96 .function void W.object_function(W a0) { 97 return.void 98 } 99 .function void static_function() { 100 return.void 101 } 102 103 .function i32 main() { 104 ldai.64 1 105 ststatic.64 %s 106 cases: 107 - values: 108 - W.fu1 109 tags: [verifier] 110 runner-options: ['verifier-failure', 'verifier-config'] 111 bugid: ['1324', '1828'] 112 - values: 113 - W.fi8 114 tags: [verifier] 115 runner-options: ['verifier-failure', 'verifier-config'] 116 bugid: ['1324', '1828'] 117 - values: 118 - W.fu16 119 tags: [verifier] 120 runner-options: ['verifier-failure', 'verifier-config'] 121 bugid: ['1324', '1828'] 122 - values: 123 - W.fi16 124 tags: [verifier] 125 runner-options: ['verifier-failure', 'verifier-config'] 126 bugid: ['1324', '1828'] 127 - values: 128 - W.fi32 129 tags: [verifier] 130 runner-options: ['verifier-failure', 'verifier-config'] 131 bugid: ['1324', '1828'] 132 - values: 133 - W.fi64 134 tags: [verifier] 135 runner-options: ['verifier-failure', 'verifier-config'] 136 bugid: ['1324', '1828'] 137 - values: 138 - W.ff32 139 tags: [verifier] 140 runner-options: ['verifier-failure', 'verifier-config'] 141 bugid: ['1324', '1828'] 142 - values: 143 - W.ff64 144 tags: [verifier] 145 runner-options: ['verifier-failure', 'verifier-config'] 146 bugid: ['1324', '1828'] 147 - values: 148 - W.fW 149 tags: [verifier] 150 runner-options: ['verifier-failure', 'verifier-config'] 151 bugid: ['1324', '1828'] 152 - values: 153 - W.fi32Array 154 tags: [verifier] 155 runner-options: ['verifier-failure', 'verifier-config'] 156 bugid: ['1324', '1828'] 157 - values: 158 - W.fWArray 159 tags: [verifier] 160 runner-options: ['verifier-failure', 'verifier-config'] 161 bugid: ['1324', '1828'] 162 - values: 163 - W 164 runner-options: ['compile-failure'] 165 - values: 166 - W.object_function 167 runner-options: ['compile-failure'] 168 - values: 169 - static_function 170 runner-options: ['compile-failure'] 171 - values: 172 - unknown_function 173 runner-options: ['compile-failure'] 174 - values: 175 - 0 176 runner-options: ['compile-failure'] 177 - values: 178 - -1.1 179 runner-options: ['compile-failure'] 180 - values: 181 - "null" 182 runner-options: ['compile-failure'] 183 - values: 184 - "\"abc\"" 185 runner-options: ['compile-failure'] 186 187 188 - file-name: "with_wrong_field_size" 189 description: Check that verifier reports an error when the field_id resolves to a field with size that is not corresponding to bytecode 190 isa: 191 verification: 192 - field_id_size 193 header-template: ['pandasm_header'] 194 check-type: exit-positive 195 tags: ['verifier'] 196 runner-options: ['verifier-failure', 'verifier-config'] 197 bugid: ['1834'] 198 code-template: | 199 .function i32 main() { 200 %s 201 ststatic.64 *s 202 template-cases: 203 - values: 204 - ldai.64 0x5a5a5a5a5a5a5a5a 205 - values: 206 - fldai.64 3.1415926 207 cases: 208 - values: 209 - R.fu1 210 - values: 211 - R.fu8 212 - values: 213 - R.fi8 214 - values: 215 - R.fu16 216 - values: 217 - R.fi16 218 - values: 219 - R.fu32 220 - values: 221 - R.fi32 222 - values: 223 - R.ff32 224 bugid: ['6094'] 225 - values: 226 - R.fObj 227 - values: 228 - R.fObjArray 229 - values: 230 - R.fi32Array 231 232 233 - file-name: "with_wrong_acc_type" 234 description: Check that verifier reports error when the accumulator contains a value of type not corresponding to the bytecode 235 isa: 236 verification: 237 - acc_type 238 header-template: ['pandasm_header'] 239 check-type: exit-positive 240 tags: ['verifier'] 241 runner-options: ['verifier-failure', 'verifier-config'] 242 bugid: ['1834'] 243 code-template: | 244 245 .function i32 main() { 246 *s 247 ststatic.64 %s 248 cases: 249 - values: 250 - ldai 0 251 - values: 252 - ldai.64 0 253 id: i64 254 - values: 255 - fldai 0.0 256 - values: 257 - fldai.64 0.0 258 id: f64 259 - values: 260 - lda.null 261 - values: 262 - lda.str "abc" 263 - values: 264 - | 265 # 266 movi v1, 10 267 newarr v1, v1, i32[] 268 lda.obj v1 269 template-cases: 270 - values: 271 - R.fu64 272 exclude: [i64] 273 - values: 274 - R.fi64 275 exclude: [i64] 276 - values: 277 - R.ff64 278 exclude: [f64] 279 bugid: ['6094'] 280 281 282 - file-name: "into_all_field_types" 283 description: Check that accumulator value is stored in field 284 isa: 285 instructions: 286 - sig: ststatic.64 field_id 287 acc: in:b64 288 format: [op_id_16] 289 header-template: ['pandasm_header'] 290 check-type: exit-positive 291 tags: ['tsan', 'irtoc_ignore'] 292 code-template: | 293 294 .function i32 main() { 295 %s 296 ststatic.64 R.%s 297 lda.null 298 ldstatic.64 R.%s 299 %s 300 jeqz success 301 ldai 1 302 return 303 success: 304 cases: 305 # u64 306 - values: 307 - ldai.64 0x0000000000000000 308 - fu64 309 - fu64 310 - | 311 movi.64 v1, 0x0000000000000000 312 ucmp.64 v1 313 - values: 314 - ldai.64 0xffffffffffffffff 315 - fu64 316 - fu64 317 - | 318 movi.64 v1, 0xffffffffffffffff 319 ucmp.64 v1 320 - values: 321 - ldai.64 0xa5a5a5a5a5a5a5a5 322 - fu64 323 - fu64 324 - | 325 movi.64 v1, 0xa5a5a5a5a5a5a5a5 326 ucmp.64 v1 327 # i64 328 - values: 329 - ldai.64 0 330 - fi64 331 - fi64 332 - | 333 movi.64 v1, 0 334 cmp.64 v1 335 - values: 336 - ldai.64 -1 337 - fi64 338 - fi64 339 - | 340 movi.64 v1, -1 341 cmp.64 v1 342 - values: 343 - ldai.64 -6510615555426900571 344 - fi64 345 - fi64 346 - | 347 movi.64 v1, -6510615555426900571 348 cmp.64 v1 349 # f64 350 - values: 351 - fldai.64 0.0 352 - ff64 353 - ff64 354 - | 355 fmovi.64 v1, 0.0 356 fcmpg.64 v1 357 - values: 358 - fldai.64 -6510615555426900571.0 359 - ff64 360 - ff64 361 - | 362 fmovi.64 v1, -6510615555426900571.0 363 fcmpg.64 v1 364 - values: 365 - fldai.64 0x7FFFFFFFFFFFFFFF # NaN 366 - ff64 367 - ff64 368 - | 369 fmovi.64 v1, 0.0 370 fcmpg.64 v1 371 subi 1 372 - values: 373 - fldai.64 0x7ff0000000000000 # + Inf 374 - ff64 375 - ff64 376 - | 377 fmovi.64 v1, 0x7ff0000000000000 378 fcmpg.64 v1 379 - values: 380 - fldai.64 0xfff0000000000000 # - Inf 381 - ff64 382 - ff64 383 - | 384 fmovi.64 v1, 0xfff0000000000000 385 fcmpg.64 v1 386 387 - file-name: "x_init_p" 388 description: Check that ExceptionInInitializerError is thrown if an unexpected exception occurs in static initializer. 389 isa: 390 exceptions: 391 - x_init 392 header-template: [] 393 check-type: empty 394 tags: ['tsan', 'irtoc_ignore'] 395 bugid: ['5330'] 396 code-template: | 397 398 .language PandaAssembly 399 400 .record panda.ExceptionInInitializerError <external> 401 .record panda.NullPointerException <external> 402 .record E1 {} 403 .record R { 404 f64 ff64 <static> 405 } 406 407 .function void R.func() <cctor> { 408 %s 409 return.void 410 } 411 412 .function i32 main() { 413 begin: 414 fldai.64 3.1415926 415 ststatic.64 R.ff64 416 ldai 2 417 return 418 end: 419 catch: 420 ldai 0 421 return 422 catch_all: 423 ldai 1 424 return 425 .catch panda.ExceptionInInitializerError, begin, end, catch 426 .catchall begin, end, catch_all 427 } 428 cases: 429 - values: 430 - | 431 # 432 newobj v0, E1 433 throw v0 434 - values: 435 - | 436 # 437 newobj v0, panda.NullPointerException 438 throw v0 439 - values: 440 - | 441 # 442 movi v1, 0 443 ldai 1 444 div2 v1 # divide by zero 445 - values: 446 - | 447 # 448 movi v1, 10 449 newarr v1, v1, i32[] 450 ldai 10 451 ldarr v1 # get ArrayIndexOutOfBoundsException 452 453 - file-name: "x_init_j" 454 description: Check that ExceptionInInitializerError is thrown if an unexpected exception occurs in static initializer. 455 isa: 456 exceptions: 457 - x_init 458 header-template: [] 459 check-type: empty 460 tags: ['tsan', 'irtoc_ignore'] 461 runner-options: ['use-pa'] 462 code-template: | 463 464 .language PandaAssembly 465 466 .record panda.ExceptionInInitializerError <external> 467 .record panda.NullPointerException <external> 468 .record E1 {} 469 .record R { 470 f64 ff64 <static> 471 } 472 .record Q <panda.extends=R> { 473 f64 ff64 <static> 474 } 475 .function void R.func() <cctor> { 476 %s 477 return.void 478 } 479 480 .function i32 main() { 481 begin: 482 fldai.64 3.1415926 483 ststatic.64 Q.ff64 484 ldai 2 485 return 486 end: 487 catch: 488 ldai 0 489 return 490 catch_all: 491 ldai 1 492 return 493 .catch panda.ExceptionInInitializerError, begin, end, catch 494 .catchall begin, end, catch_all 495 } 496 cases: 497 - values: 498 - | 499 # 500 newobj v0, E1 501 throw v0 502 - values: 503 - | 504 # 505 newobj v0, panda.NullPointerException 506 throw v0 507 - values: 508 - | 509 # 510 movi v1, 0 511 ldai 1 512 div2 v1 # divide by zero 513 - values: 514 - | 515 # 516 movi v1, 10 517 newarr v1, v1, i32[] 518 ldai 10 519 ldarr v1 # get ArrayIndexOutOfBoundsException 520