Cranelift: interpreter: incorrect edge-case handling in fcvt_to_{u,s}int.i128

オープン 初心者向け
#15,198 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

@ryancbuckley がすでに取り組んでいます。

2026年11月8日 から。

  • #15199 @ryancbuckley による — オープン

評価

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

調査の方向性

floatからi128への変換付近にある cranelift/interpreter/src/step.rs と、cranelift/codegen/meta/src/shared/instructions.rs の命令ドキュメントを読む。次に runtests/i128-conversion.clif を調べ、該当するCraneliftインタープリターのテストを実行する。範囲外の符号付き変換がtrapを発生させ、符号なし変換が [2¹²⁷, 2¹²⁸) の入力に対して期待される値を返せば完了。

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

説明

bug cranelift

Minor/pedantic bug. The float-to-int128 conversions in the interpreter misbehave when passed very large (or very negative) values:

  • fcvt_to_sint.i128 returns i128::MAX or i128::MIN for out-of-range inputs. The doc comments say it should trap.
  • fcvt_to_uint.i128 and fcvt_to_uint_sat.i128 clamp some large inputs (in the interval [2¹²⁷, 2¹²⁸)) to i128::MAX, even though those values should fit in the result.

I noticed this issue because runtests/i128-conversion.clif matches the implementation, so it has three incorrect expectations:

  • Line 14:
    • ; run: %fcvt_to_uint_i128(0x1.fffffep127) == 170141183460469231731687303715884105727
    • Should return: 340282346638528859811704183484516925440
  • The nearly identical call on line 40 should have the same result:
    • ; run: %fcvt_to_uint_sat_i128(0x1.fffffep127) == 170141183460469231731687303715884105727
  • Line 28:
    • ; run: %fcvt_to_sint_i128(0x1.fffffep127) == 170141183460469231731687303715884105727
    • Should trap

The root cause is that the interpreter's fcvt_to_uint and fcvt_to_sint cast the input with as i128 before the bounds check.

主要言語
Rust
スター
18.8k
フォーク
1.9k
平均マージ
1日 3時間
マージ済み PR(30日)
380

環境構築

はじめの一歩

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

bytecodealliance/wasmtime のほかの issue

bytecodealliance/wasmtime の issue をすべて見る

似ている issue

Rust の issue をもっと見る

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

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