ssm-lang / Scoria

This is an embedding of the Sparse Synchronous Model, in Haskell!
BSD 3-Clause "New" or "Revised" License
4 stars 0 forks source link

Integer overflow in interpreter might be UB #84

Open j-hui opened 3 years ago

j-hui commented 3 years ago

Follow on from #32 --- I patched up the generated code to only use C's unsigned ints, for which we can rely on reliably wrapping around on overflow, but the matter of what happens with the Haskell-side interpreter is another matter. In particular, overflow for Int seems to be undefined no matter what. We're not encountering any failed test cases yet, but we should account for this at some point, with some bounds checks, or by converting all arithmetic to take place with Integer and perform the wraparound ourselves.

j-hui commented 3 years ago

Leaving a note here that overflow of fixed precision integers in Haskell is undefined. In fact, the specific behavior differ within the same platform/compiler implementation: https://rosettacode.org/wiki/Integer_overflow#Haskell.