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

未关闭 适合新手
#15,198 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@ryancbuckley 已经在做这个了。

开始于 2026年11月8日。

  • #15199 来自 @ryancbuckley —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
83/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
rust
领域
backend

调研方向

阅读 cranelift/interpreter/src/step.rs 中 float 到 i128 转换附近的代码,以及 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 小时
30 天内合并 PR
357

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

bytecodealliance/wasmtime 的其他 Issue

查看 bytecodealliance/wasmtime 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。