Skip to content

Commit 18e6776

Browse files
LiedtkeV8 LUCI CQ
authored andcommitted
[compiler][wasm] Fix endless loop in WasmTyper
The graph builder was applying a TypeGuard into the wrong control chain. In this case the br_on_non_null implementation added a TypeGuard for the non-null type before performing the actual branch. The br_on_non_null target is anyways going to merge controls with some other branch and Turboshaft is hopefully making all this code oboslete soon, so the easiest and safest fix is to drop the TypeGuard completely. Fixed: 361862737 Change-Id: Ifc1c34ab726576b861d3d5dc6f6a9d20e93d4af0 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/5826664 Auto-Submit: Matthias Liedtke <[email protected]> Reviewed-by: Jakob Kummerow <[email protected]> Commit-Queue: Jakob Kummerow <[email protected]> Cr-Commit-Position: refs/heads/main@{#95897}
1 parent 94cb51a commit 18e6776

2 files changed

Lines changed: 32 additions & 2 deletions

File tree

src/wasm/graph-builder-interface.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,8 +1206,7 @@ class WasmGraphBuildingInterface {
12061206

12071207
void BrOnNonNull(FullDecoder* decoder, const Value& ref_object, Value* result,
12081208
uint32_t depth, bool /* drop_null_on_fallthrough */) {
1209-
result->node =
1210-
builder_->TypeGuard(ref_object.node, ref_object.type.AsNonNull());
1209+
result->node = ref_object.node;
12111210
SsaEnv* false_env = ssa_env_;
12121211
SsaEnv* true_env = Split(decoder->zone(), false_env);
12131212
false_env->SetNotMerged();
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright 2024 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+
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
6+
7+
// This test case reproduces a case in Turbofan where the WasmTyper was
8+
// flip-flopping between two different states never reaching a fix point.
9+
const builder = new WasmModuleBuilder();
10+
let $array1 = builder.addArray(kWasmI16, true, kNoSuperType, true);
11+
let loopSig = builder.addType(makeSig([kWasmFuncRef], []));
12+
let funcEndless = builder.addFunction('funcEndless', kSig_v_v).exportFunc()
13+
.addLocals(kWasmFuncRef, 1) // $var0
14+
.addBody([
15+
kExprRefNull, kFuncRefCode,
16+
kExprLoop, loopSig,
17+
kExprLocalTee, 0, // $var0
18+
kExprBrOnNonNull, 0,
19+
kExprLocalGet, 0, // $var0
20+
kExprRefAsNonNull,
21+
kExprBrOnNonNull, 0,
22+
kExprEnd,
23+
24+
// Use something with a gc prefix to enable the WasmTyper.
25+
kExprRefNull, $array1,
26+
kGCPrefix, kExprArrayLen,
27+
kExprDrop,
28+
]);
29+
30+
const instance = builder.instantiate();
31+
assertTraps(kTrapNullDereference, () => instance.exports.funcEndless(null));

0 commit comments

Comments
 (0)