google-research/dex-lang

Do unsigned remainder on unsigned types

Open

#1,211 建立於 2023年2月5日

在 GitHub 查看
 (1 留言) (1 反應) (0 負責人)Haskell (1,681 star) (116 fork)batch import
buggood first issue

描述

Manifestation:

big = 2147483647
rem (big + 1) big
> 4294967295

Expected the answer to be 1.

(Note that big + 1 doesn't overflow the underlying Word32 -- it's just the rem operation messing up).

The cause is https://github.com/google-research/dex-lang/blob/c996e988d07f4bec0495136c9d4ca51bcb0c431c/src/lib/ImpToLLVM.hs#L614, which unconditionally emits a signed remainder instruction, regardless of whether the Dex type is meant to be signed or unsigned.

貢獻者指南