OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 load("test/mjsunit/wasm/wasm-constants.js"); |
| 6 load("test/mjsunit/wasm/wasm-module-builder.js"); |
| 7 |
| 8 (function AddTest() { |
| 9 let builder = new WasmModuleBuilder(); |
| 10 |
| 11 builder.addFunction("main", kSig_i_v) |
| 12 .addBody([ |
| 13 kExprBlock, kWasmStmt, |
| 14 kExprI64Const, 0, |
| 15 // 0x80 ... 0x10 is the LEB encoding of 0x100000000. This is chosen so |
| 16 // that the 64-bit constant has a non-zero top half. In this bug, the |
| 17 // top half was clobbering eax, leading to the function return 1 rather |
| 18 // than 0. |
| 19 kExprI64Const, 0x80, 0x80, 0x80, 0x80, 0x10, |
| 20 kExprI64Add, |
| 21 kExprI64Eqz, |
| 22 kExprBrIf, 0, |
| 23 kExprI32Const, 0, |
| 24 kExprReturn, |
| 25 kExprEnd, |
| 26 kExprI32Const, 0 |
| 27 ]) |
| 28 .exportFunc(); |
| 29 let module = builder.instantiate(); |
| 30 assertEquals(0, module.exports.main()); |
| 31 })(); |
| 32 |
| 33 (function SubTest() { |
| 34 let builder = new WasmModuleBuilder(); |
| 35 |
| 36 builder.addFunction("main", kSig_i_v) |
| 37 .addBody([ |
| 38 kExprBlock, kWasmStmt, |
| 39 kExprI64Const, 0, |
| 40 // 0x80 ... 0x10 is the LEB encoding of 0x100000000. This is chosen so |
| 41 // that the 64-bit constant has a non-zero top half. In this bug, the |
| 42 // top half was clobbering eax, leading to the function return 1 rather |
| 43 // than 0. |
| 44 kExprI64Const, 0x80, 0x80, 0x80, 0x80, 0x10, |
| 45 kExprI64Sub, |
| 46 kExprI64Eqz, |
| 47 kExprBrIf, 0, |
| 48 kExprI32Const, 0, |
| 49 kExprReturn, |
| 50 kExprEnd, |
| 51 kExprI32Const, 0 |
| 52 ]) |
| 53 .exportFunc(); |
| 54 let module = builder.instantiate(); |
| 55 assertEquals(0, module.exports.main()); |
| 56 })(); |
OLD | NEW |