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: PandaAssembly 16 template: | 17 .language PandaAssembly 18 19tests: 20 - file-name: "return.void" 21 isa: 22 title: Return from a void method 23 description: > 24 Return from the current method, i.e. restore the frame of method invoker and return control to the invoker. 25 Caller should treat accumulator value as undefined and cannot use it until accumulator definition in the caller 26 frame. 27 verification: 28 - none 29 exceptions: 30 - x_none 31 commands: 32 - file-name: "call_s_p" 33 bugid: ['5271'] 34 isa: 35 instructions: 36 - sig: return.void 37 acc: none 38 format: [op_none] 39 header-template: [] 40 code-template: | 41 .function void func(%s) { 42 return.void 43 } 44 45 .function i32 main() { 46 %s 47 call.short func%s 48 check-type: exit-positive 49 description: Check 'return.void' returns control flow to caller in Pandasm context with static call. 50 cases: 51 - values: 52 - '' 53 - '' 54 - '' 55 - values: 56 - 'i32 a0' 57 - 'movi v0, 0' 58 - ', v0' 59 - values: 60 - 'i32 a0, f64 a1' 61 - | 62 # 63 movi v0, 0 64 fmovi.64 v1, 1.2 65 - ', v0, v1' 66 67 - file-name: "call_s_j" 68 isa: 69 instructions: 70 - sig: return.void 71 acc: none 72 format: [op_none] 73 header-template: [PandaAssembly] 74 runner-options: [use-pa] 75 code-template: | 76 .function void func(%s) { 77 return.void 78 } 79 80 .function i32 main() { 81 %s 82 call.short func%s 83 check-type: exit-positive 84 description: Check 'return.void' returns control flow to caller in PandaAssembly context with static call. 85 cases: 86 - values: 87 - '' 88 - '' 89 - '' 90 - values: 91 - 'i32 a0' 92 - 'movi v0, 0' 93 - ', v0' 94 - values: 95 - 'i32 a0, f64 a1' 96 - | 97 # 98 movi v0, 0 99 fmovi.64 v1, 1.2 100 - ', v0, v1' 101 102 - file-name: "call_v_p" 103 isa: 104 instructions: 105 - sig: return.void 106 acc: none 107 format: [op_none] 108 header-template: [] 109 code-template: | 110 .record R {} 111 .function void R.func(R a0%s) { 112 return.void 113 } 114 115 .function i32 main() { 116 %s 117 newobj v10, R 118 call.virt R.func, v10%s 119 check-type: exit-positive 120 description: Check 'return.void' returns control flow to caller in Pandasm context with virtual call. 121 cases: 122 - values: 123 - '' 124 - '' 125 - '' 126 - values: 127 - ', i32 a1' 128 - 'movi v0, 0' 129 - ', v0' 130 - values: 131 - ', i32 a1, f64 a2' 132 - | 133 # 134 movi v0, 0 135 fmovi.64 v1, 1.2 136 - ', v0, v1' 137 138 - file-name: "call_v_j" 139 isa: 140 instructions: 141 - sig: return.void 142 acc: none 143 format: [op_none] 144 header-template: [PandaAssembly] 145 runner-options: [use-pa] 146 code-template: | 147 .record R {} 148 .function void R.func(R a0%s) { 149 return.void 150 } 151 152 .function i32 main() { 153 %s 154 newobj v10, R 155 call.virt R.func, v10%s 156 check-type: exit-positive 157 description: Check 'return.void' returns control flow to caller in PandaAssembly context with virtual call. 158 cases: 159 - values: 160 - '' 161 - '' 162 - '' 163 - values: 164 - ', i32 a1' 165 - 'movi v0, 0' 166 - ', v0' 167 - values: 168 - ', i32 a1, f64 a2' 169 - | 170 # 171 movi v0, 0 172 fmovi.64 v1, 1.2 173 - ', v0, v1' 174 175 - file-name: "type" 176 tags: [verifier] 177 bugid: ['1324'] 178 runner-options: ['verifier-failure', 'verifier-config'] 179 isa: 180 instructions: 181 - sig: return.void 182 acc: none 183 format: [op_none] 184 header-template: [] 185 code-template: | 186 .record panda.Object <external> 187 .function %s func() { 188 *s 189 return.void 190 } 191 192 .function i32 main() { 193 call.short func 194 check-type: exit-positive 195 description: Check that 'return.void' is used with correct function return type. 196 template-cases: 197 - values: [u1] 198 - values: [i8] 199 - values: [u8] 200 - values: [i16] 201 - values: [u16] 202 - values: [i32] 203 - values: [u32] 204 - values: [i64] 205 - values: [u64] 206 - values: [f32] 207 - values: [f64] 208 - values: [panda.Object] 209 cases: 210 - values: [''] 211 - values: [ldai 0] 212 - values: [ldai.64 0] 213 - values: [fldai 0] 214 - values: [fldai.64 0] 215 - values: [lda.null] 216 - values: [lda.str "some string"] 217 - values: 218 - initobj Obj.ctor 219 case-header-template: [obj_ctor] 220 - values: 221 - lda.type Obj 222 case-header-template: [obj_ctor] 223 224 - file-name: "wrong_return" 225 tags: [verifier] 226 runner-options: ['verifier-failure', 'verifier-config'] 227 isa: 228 instructions: 229 - sig: return.void 230 acc: none 231 format: [op_none] 232 header-template: [] 233 code-template: | 234 .function void func() { 235 %s 236 } 237 238 .function i32 main() { 239 call.short func 240 check-type: exit-positive 241 description: Check the verifier behavior when expected 'return.void' is not given. 242 cases: 243 - values: 244 - | 245 # 246 lda.null 247 - values: 248 - | 249 # 250 ldai 0 251 return 252 - values: 253 - | 254 # 255 fldai.64 1.0 256 return.64 257 - values: 258 - | 259 # 260 lda.str "test" 261 return.obj 262 263 - file-name: "regs_restore" 264 isa: 265 instructions: 266 - sig: return.void 267 acc: none 268 format: [op_none] 269 header-template: [] 270 check-type: none 271 code-template: | 272 .function void func(%s) { 273 %s 274 return.void 275 } 276 277 .function i32 main() { 278 %s 279 call.short func%s 280 %s 281 description: Check that after 'return.void' register are restored in caller. 282 cases: 283 - values: 284 - '' 285 - '' 286 - 'movi v0, 0x12345678' 287 - '' 288 - | 289 # 290 ldai 0x12345678 291 jne v0, exit_failure 292 ldai 0 293 return 294 exit_failure: ldai 1 295 return 296 description: "Register is not used in function." 297 - values: 298 - 'i32 a0' 299 - 'movi v0, 0x87654321' 300 - 'movi v0, 0x12345678' 301 - ', v0' 302 - | 303 # 304 ldai 0x12345678 305 jne v0, exit_failure 306 ldai 0 307 return 308 exit_failure: ldai 1 309 return 310 description: "Register is used in function." 311 312 - values: 313 - 'i32 a0' 314 - '' 315 - 'movi v0, 0x12345678' 316 - ', v0' 317 - | 318 # 319 ldai 0x12345678 320 jne v0, exit_failure 321 ldai 0 322 return 323 exit_failure: ldai 1 324 return 325 description: "Register is not used in function." 326 327 - values: 328 - 'f64 a0, i64 a1' 329 - | 330 # 331 fmovi.64 v0, 0 332 movi.64 v1, 0 333 - | 334 # 335 fmovi.64 v0, 3.1415926535 336 movi.64 v1, 0x123456789ABCDEF0 337 - ', v0, v1' 338 - | 339 # 340 fldai.64 3.1415926535 341 fcmpg.64 v0 342 jeqz check2 343 ldai 1 344 return 345 check2: 346 ldai.64 0x123456789ABCDEF0 347 cmp.64 v1 348 jnez exit_failure 349 ldai 0 350 return 351 exit_failure: 352 ldai 1 353 return 354 description: "Registers are used in function." 355 356 - file-name: "undef_acc_s_p" 357 isa: 358 instructions: 359 - sig: return.void 360 acc: none 361 format: [op_none] 362 tags: [verifier] 363 bugid: ['1324'] 364 runner-options: ['verifier-failure', 'verifier-config'] 365 description: Check accumulator value if undefined after 'return.void' in Pandasm context with static call. 366 header-template: [] 367 code-template: | 368 .function void func() { 369 return.void 370 } 371 372 .function i32 main() { 373 ldai 0 374 call.short func 375 sta v0 376 check-type: exit-positive 377 378 - file-name: "undef_acc_s_j" 379 isa: 380 instructions: 381 - sig: return.void 382 acc: none 383 format: [op_none] 384 tags: [verifier] 385 bugid: ['1324'] 386 runner-options: ['verifier-failure', 'verifier-config', 'use-pa'] 387 description: Check accumulator value if undefined after 'return.void' in PandaAssembly context with static call. 388 header-template: [PandaAssembly] 389 code-template: | 390 .function void func() { 391 return.void 392 } 393 394 .function i32 main() { 395 ldai 0 396 call.short func 397 sta v0 398 check-type: exit-positive 399 400 - file-name: "undef_acc_v_p" 401 isa: 402 instructions: 403 - sig: return.void 404 acc: none 405 format: [op_none] 406 tags: [verifier] 407 bugid: ['1324'] 408 runner-options: ['verifier-failure', 'verifier-config'] 409 description: Check accumulator value if undefined after 'return.void' in Pandasm context with virtual call. 410 header-template: [] 411 code-template: | 412 .record R {} 413 .function void R.func(R a0) { 414 return.void 415 } 416 417 .function i32 main() { 418 ldai 0 419 newobj v10, R 420 call.virt.short R.func, v10 421 sta v0 422 check-type: exit-positive 423 424 - file-name: "undef_acc_v_j" 425 isa: 426 instructions: 427 - sig: return.void 428 acc: none 429 format: [op_none] 430 tags: [verifier] 431 bugid: ['1324'] 432 runner-options: ['verifier-failure', 'verifier-config', 'use-pa'] 433 description: Check accumulator value if undefined after 'return.void' in PandaAssembly context with virtual call. 434 header-template: [PandaAssembly] 435 code-template: | 436 .record R {} 437 .function void R.func(R a0) { 438 return.void 439 } 440 441 .function i32 main() { 442 ldai 0 443 newobj v10, R 444 call.virt.short R.func, v10 445 sta v0 446 check-type: exit-positive 447