summaryrefslogtreecommitdiff
path: root/deps/v8/test/mjsunit/regress/wasm/regress-crbug-1407594.js
blob: 943ba85be46346c5ed6152ba7029e44f0889b8a2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Copyright 2023 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');

let builder = new WasmModuleBuilder();
builder.addMemory(1, 1, false);
builder.addDataSegment(0, [0x78, 0x56, 0x34, 0x12]);

let spiller = builder.addFunction('spiller', kSig_v_v).addBody([]);

builder.addFunction('main', kSig_l_v)
    .exportFunc()
    .addLocals(kWasmI64, 1)
    .addBody([
      // Initialize {var0} to 0x12345678 via a zero-extended 32-bit load.
      kExprI32Const, 0,
      kExprI64LoadMem32U, 2, 0,
      kExprLocalSet, 0,
      kExprCallFunction, spiller.index,
      // The observable effect of this loop is that {var0} is left-shifted
      // until it ends in 0x..000000. The details are specifically crafted
      // to recreate a particular pattern of spill slot moves.
      kExprLoop, kWasmVoid,
        kExprI32Const, 0,
        kExprI32LoadMem, 2, 0,
        kExprI32Eqz,
        // This block is never taken; it only serves to influence register
        // allocator choices.
        kExprIf, kWasmVoid,
          kExprLocalGet, 0,
          kExprI64Const, 1,
          kExprI64And,
          kExprLocalSet, 0,
        kExprEnd,  // if
        kExprLocalGet, 0,
        kExprI64Const, 1,
        kExprI64And,
        kExprI64Eqz,
        // This block is always taken; it is conditional in order to influence
        // register allocator choices.
        kExprIf, kWasmVoid,
          kExprLocalGet, 0,
          kExprI64Const, 8,
          kExprI64Shl,
          kExprLocalSet, 0,
        kExprEnd,  // if
        kExprBlock, kWasmVoid,
          kExprLocalGet, 0,
          ...wasmI64Const(0xFFFFFF),
          kExprI64And,
          kExprI64Eqz,
          kExprI32Eqz,
          kExprCallFunction, spiller.index,
          kExprBrIf, 1,
        kExprEnd,  // block
        kExprCallFunction, spiller.index,
      kExprEnd,  // loop
      kExprLocalGet, 0,
    ]);

let instance = builder.instantiate();
assertEquals("12345678000000", instance.exports.main().toString(16));