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 <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 R fR <static> 43 R[] fRArray <static> 44 panda.Object fObj <static> 45 panda.Object[] fObjArray <static> 46 } 47 .function void R.ctor(R a0) <ctor> { 48 return.void 49 } 50 51 - name: java_header 52 template: | 53 .language Java 54 55 .record java.lang.Object <external> 56 .function void java.lang.Object.ctor(java.lang.Object a0) <external, ctor> 57 58 .record I <java.interface> {} 59 60 .record Q <java.implements=I> {} 61 .function void Q.ctor(Q a0) <ctor> { 62 return.void 63 } 64 65 .record R <java.extends=Q> { 66 u1 fu1 <static> 67 u8 fu8 <static> 68 i8 fi8 <static> 69 u16 fu16 <static> 70 i16 fi16 <static> 71 u32 fu32 <static> 72 i32 fi32 <static> 73 u64 fu64 <static> 74 i64 fi64 <static> 75 f32 ff32 <static> 76 f64 ff64 <static> 77 # objects 78 i32[] fi32Array <static> 79 Q fQ <static> 80 Q[] fQArray <static> 81 R fR <static> 82 R[] fRArray <static> 83 I fI <static> 84 I[] fIArray <static> 85 java.lang.Object fObj <static> 86 java.lang.Object[] fObjArray <static> 87 } 88 .function void R.ctor(R a0) <ctor> { 89 return.void 90 } 91 92tests: 93 - file-name: "ststatic.obj" 94 isa: 95 title: Store to static field 96 description: > 97 Store accumulator content into static field by field_id. 98 instructions: 99 - sig: ststatic.obj field_id 100 acc: in:ref 101 format: [op_id_16] 102 commands: 103 104 - file-name: "check_if_acc_initialized" 105 description: Check that verifier reports an error if accumulator is not initialized 106 isa: 107 description: Store accumulator content into static field by field_id. 108 header-template: ['pandasm_header'] 109 check-type: exit-positive 110 tags: ['verifier'] 111 bugid: ['1324'] 112 runner-options: ['verifier-failure', 'verifier-debug-config'] 113 code-template: | 114 115 .function i32 main() { 116 # acc (value) not initialized, verifier error expected 117 ststatic.obj R.fR 118 119 120 - file-name: "with_non_static_field_id" 121 bugid: ['1324'] 122 description: Check that verifier reports error when the field_id doesn't resolve to a static valid field 123 isa: 124 verification: 125 - field_id_static 126 header-template: ['pandasm_header'] 127 check-type: exit-positive 128 code-template: | 129 .record W { 130 u1 fu1 131 i8 fi8 132 u16 fu16 133 i16 fi16 134 i32 fi32 135 i64 fi64 136 f32 ff32 137 f64 ff64 138 W fW 139 i32[] fi32Array 140 W[] fWArray 141 } 142 .function void W.object_function(W a0) { 143 return.void 144 } 145 .function void static_function() { 146 return.void 147 } 148 149 .function i32 main() { 150 lda.null 151 ststatic.obj %s 152 cases: 153 - values: 154 - W.fu1 155 tags: [verifier] 156 runner-options: ['verifier-failure', 'verifier-debug-config'] 157 bugid: ['1324', '1828'] 158 - values: 159 - W.fi8 160 tags: [verifier] 161 runner-options: ['verifier-failure', 'verifier-debug-config'] 162 bugid: ['1324', '1828'] 163 - values: 164 - W.fu16 165 tags: [verifier] 166 runner-options: ['verifier-failure', 'verifier-debug-config'] 167 bugid: ['1324', '1828'] 168 - values: 169 - W.fi16 170 tags: [verifier] 171 runner-options: ['verifier-failure', 'verifier-debug-config'] 172 bugid: ['1324', '1828'] 173 - values: 174 - W.fi32 175 tags: [verifier] 176 runner-options: ['verifier-failure', 'verifier-debug-config'] 177 bugid: ['1324', '1828'] 178 - values: 179 - W.fi64 180 tags: [verifier] 181 runner-options: ['verifier-failure', 'verifier-debug-config'] 182 bugid: ['1324', '1828'] 183 - values: 184 - W.ff32 185 tags: [verifier] 186 runner-options: ['verifier-failure', 'verifier-debug-config'] 187 bugid: ['1324', '1828'] 188 - values: 189 - W.ff64 190 tags: [verifier] 191 runner-options: ['verifier-failure', 'verifier-debug-config'] 192 bugid: ['1324', '1828'] 193 - values: 194 - W.fW 195 tags: [verifier] 196 runner-options: ['verifier-failure', 'verifier-debug-config'] 197 bugid: ['1324', '1828'] 198 - values: 199 - W.fi32Array 200 tags: [verifier] 201 runner-options: ['verifier-failure', 'verifier-debug-config'] 202 bugid: ['1324', '1828'] 203 - values: 204 - W.fWArray 205 tags: [verifier] 206 runner-options: ['verifier-failure', 'verifier-debug-config'] 207 bugid: ['1324', '1828'] 208 - values: 209 - W 210 runner-options: ['compile-failure'] 211 - values: 212 - W.object_function 213 runner-options: ['compile-failure'] 214 - values: 215 - static_function 216 runner-options: ['compile-failure'] 217 - values: 218 - unknown_function 219 runner-options: ['compile-failure'] 220 - values: 221 - 0 222 runner-options: ['compile-failure'] 223 - values: 224 - -1.1 225 runner-options: ['compile-failure'] 226 - values: 227 - "null" 228 runner-options: ['compile-failure'] 229 - values: 230 - "\"abc\"" 231 runner-options: ['compile-failure'] 232 233 234 - file-name: "with_wrong_acc_type_pa" 235 description: Check that verifier reports an error when the accumulator contains a value of type not corresponding to the bytecode 236 isa: 237 verification: 238 - acc_type 239 header-template: ['pandasm_header'] 240 check-type: exit-positive 241 tags: ['verifier'] 242 runner-options: ['verifier-failure', 'verifier-debug-config'] 243 code-template: | 244 245 .function i32 main() { 246 %s 247 ststatic.obj %s 248 cases: 249 # store into object type field 250 - values: 251 - ldai 0 252 - R.fQ 253 bugid: ['1324', '1834'] 254 - values: 255 - ldai.64 1 256 - R.fQ 257 bugid: ['1324', '1834'] 258 - values: 259 - fldai.64 0x7FFFFFFFFFFFFFFF 260 - R.fQ 261 bugid: ['1324', '1834'] 262 - values: 263 - lda.type R 264 - R.fQ 265 bugid: ['1834'] 266 - values: 267 - | 268 movi v1, 10 269 newarr v1, v1, Q[] 270 lda.obj v1 271 - R.fQ 272 bugid: ['1834'] 273 # store into object array type field 274 - values: 275 - ldai 0 276 - R.fQArray 277 bugid: ['1324', '1834'] 278 - values: 279 - ldai.64 1 280 - R.fQArray 281 bugid: ['1324', '1834'] 282 - values: 283 - fldai.64 0x7FFFFFFFFFFFFFFF 284 - R.fQArray 285 bugid: ['1324', '1834'] 286 - values: 287 - initobj Q.ctor 288 - R.fQArray 289 bugid: ['1834'] 290 - values: 291 - | 292 movi v1, 10 293 newarr v1, v1, R[] 294 lda.obj v1 295 - R.fQArray 296 bugid: ['1834'] 297 # store into i32[] array field 298 - values: 299 - ldai 0 300 - R.fi32Array 301 bugid: ['1324', '1834'] 302 - values: 303 - ldai.64 1 304 - R.fi32Array 305 bugid: ['1324', '1834'] 306 - values: 307 - fldai.64 0x7FFFFFFFFFFFFFFF 308 - R.fi32Array 309 bugid: ['1324', '1834'] 310 - values: 311 - lda.type R 312 - R.fi32Array 313 bugid: ['1834'] 314 - values: 315 - | 316 movi v1, 10 317 newarr v1, v1, Q[] 318 lda.obj v1 319 - R.fi32Array 320 bugid: ['1834'] 321 322 323 - file-name: "into_all_field_types_pa" 324 description: Check that accumulator value is stored in field 325 isa: 326 description: Store accumulator content into static field by field_id. 327 header-template: ['pandasm_header'] 328 check-type: exit-positive 329 tags: ['tsan'] 330 code-template: | 331 332 .function i32 main() { 333 %s 334 sta.obj v7 335 ststatic.obj R.%s 336 lda.null 337 ldstatic.obj R.%s 338 jeq.obj v7, success 339 ldai 1 340 return 341 success: 342 cases: 343 - values: 344 - | 345 # store null into Q type field 346 lda.null 347 - fQ 348 - fQ 349 - values: 350 - | 351 # store null into Q[] type field 352 lda.null 353 - fQArray 354 - fQArray 355 - values: 356 - | 357 # store Q into Q type field 358 initobj Q.ctor 359 - fQ 360 - fQ 361 - values: 362 - | 363 # store Q[] into Q[] type field 364 movi v1, 10 365 newarr v1, v1, Q[] 366 lda.obj v1 367 - fQArray 368 - fQArray 369 370 371 - file-name: "x_init_p" 372 description: Check that ExceptionInInitializerError is thrown if an unexpected exception occurs in static initializer. 373 isa: 374 exceptions: 375 - x_init 376 header-template: [] 377 check-type: empty 378 tags: ['tsan'] 379 bugid: ['5330'] 380 ignore: true 381 code-template: | 382 383 .language PandaAssembly 384 385 .record panda.ExceptionInInitializerError <external> 386 .record panda.NullPointerException <external> 387 .record E1 {} 388 .record R { 389 E1 fObj <static> 390 } 391 392 .function void R.func() <cctor> { 393 %s 394 return.void 395 } 396 397 .function i32 main() { 398 begin: 399 newobj v0, E1 400 lda.obj v0 401 ststatic R.fObj 402 ldai 2 403 return 404 end: 405 catch: 406 ldai 0 407 return 408 catch_all: 409 ldai 1 410 return 411 .catch panda.ExceptionInInitializerError, begin, end, catch 412 .catchall begin, end, catch_all 413 } 414 cases: 415 - values: 416 - | 417 # 418 newobj v0, E1 419 throw v0 420 - values: 421 - | 422 # 423 newobj v0, panda.NullPointerException 424 throw v0 425 - values: 426 - | 427 # 428 movi v1, 0 429 ldai 1 430 div2 v1 # divide by zero 431 - values: 432 - | 433 # 434 movi v1, 10 435 newarr v1, v1, i32[] 436 ldai 10 437 ldarr v1 # get ArrayIndexOutOfBoundsException 438 439