Page MenuHomePhabricator

[CGBuiltin] Handle unsigned mul overflow properly (PR35750)

Authored by vsk on Jan 3 2018, 2:33 PM.



r320902 fixed the IRGen for some types of checked multiplications. It
did not handle unsigned overflow correctly in the case where the signed
operand is negative (PR35750).

Eli pointed out that on overflow, the result must be equal to the unique
value that is equivalent to the mathematically-correct result modulo two
raised to the k power, where k is the number of bits in the result type.

This patch fixes the specialized IRGen from r320902 accordingly.

Testing: Apart from check-clang, I modified the test harness from
r320902 to validate the results of all multiplications -- not just the
ones which don't overflow:, rdar://34963321

Diff Detail


Event Timeline

vsk created this revision.Jan 3 2018, 2:33 PM
efriedma accepted this revision.Jan 3 2018, 2:36 PM


This revision is now accepted and ready to land.Jan 3 2018, 2:36 PM
This revision was automatically updated to reflect the committed changes.