Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

TupleOptimization: tuple swap is miscompiled

オープン
#9,210 コメント 0 件 リアクション 0 件 担当者 1 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
58/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
cpp, wasm
領域
compilers

調査の方向性

Start by running the provided test.wat reproducer with and without --tuple-optimization, then locate the TupleOptimization pass in Binaryen. The issue suggests comparing its lowering with Heap2Local's handling of struct.new. Done means the optimized swap returns 16, matching the unoptimized module; add a regression test for the reproducer.

索引モデルが issue の本文から書いたものです。

説明

Summary

--tuple-optimization splits a tuple local into scalar locals and lowers local.set $t (tuple.make a0 a1) to $t0 = a0; $t1 = a1, in order. If an operand reads an element of $t that was already overwritten (a1 = tuple.extract 0 $t), it reads the new value:

t = (t.1, t.0)   ==>   $t0 = $t1; $t1 = $t0;   // $t0 is already overwritten

The pass is in -O1 and above; a multivalue loop that swaps its parameters (plain wasm) is miscompiled by -O3, -Os, -Oz and -O4.

Evaluating the operands into temporaries first (as Heap2Local does for struct.new) would fix it.

Reproducer

test.wat:

(module
 (func (export "f") (param $x i32) (param $y i32) (result i32)
  (local $t (tuple i32 i32))
  (local.set $t (tuple.make 2 (local.get $x) (local.get $y)))
  (local.set $t (tuple.make 2 (tuple.extract 2 1 (local.get $t)) (tuple.extract 2 0 (local.get $t))))
  (tuple.extract 2 1 (local.get $t))))
$ wasm-opt test.wat --enable-multivalue -o in.wasm
$ wasm-opt test.wat --enable-multivalue --tuple-optimization -o out.wasm
$ wasmtime run --invoke f in.wasm 16 1000
16
$ wasmtime run --invoke f out.wasm 16 1000
1000

f swaps the elements of t and returns t.1, which is the original x, so the correct result is 16. V8 gives the same results.

AI was used as part of the process of finding this issue. I have manually checked and reproduced it.

主要言語
WebAssembly
スター
8.7k
フォーク
893
平均マージ
1日 14時間
マージ済み PR(30日)
77

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

WebAssembly/binaryen のほかの issue

WebAssembly/binaryen の issue をすべて見る

似ている issue

Compilers の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。