Comparing number greater than Int32.max gives false result

I haven't done the investigation, but at a guess:

  • The optimizer is folding the tautological comparison.
  • The Int8 value on the left-hand side is now unused.
  • The optimizer is eliminating the now-dead creation of an Int8 value from a literal, even though it contains a potential overflow trap.

I believe the Swift high-level optimizer is generally authorized to eliminate overflow checks if it can prove that the result of the arithmetic is unused, because otherwise we'd be extremely restricted in terms of moving arithmetic around. Obviously the result of that is really bad here; the right fix is probably that uses eliminated via tautology should still "count" somehow in terms of forcing the operands to be normally evaluated.

5 Likes