google-research/dex-lang

Do unsigned remainder on unsigned types

Open

#1,211 opened on Feb 5, 2023

View on GitHub
 (1 comment) (1 reaction) (0 assignees)Haskell (116 forks)batch import
buggood first issue

Repository metrics

Stars
 (1,681 stars)
PR merge metrics
 (No merged PRs in 30d)

Description

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.

Contributor guide