3 Commits

Author SHA1 Message Date
George Karpenkov
b97b3021fc Add checkMulAdd helper function to CheckedArithmetic
Multiplication followed by addition
(https://en.wikipedia.org/wiki/Multiply–accumulate_operation) is a
sufficiently common use-case to warrant a separate helper.

Differential Revision: https://reviews.llvm.org/D48138

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@334635 91177308-0d34-0410-b5e6-96231b3b80d8
2018-06-13 18:32:02 +00:00
George Karpenkov
ba86f98ba7 Change checked arithmetic functions API to return Optional
Returning optional is much safer.
The previous API had potential to cause use of undefined variables, if
the value passed by pointer was accidentally read afterwards.

Differential Revision: https://reviews.llvm.org/D48137

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@334634 91177308-0d34-0410-b5e6-96231b3b80d8
2018-06-13 18:31:43 +00:00
George Karpenkov
a8353210f0 Utility functions for checked arithmetic
Provide checkedAdd and checkedMul functions, providing checked
arithmetic on signed integers.

Differential Revision: https://reviews.llvm.org/D43704

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@326516 91177308-0d34-0410-b5e6-96231b3b80d8
2018-03-02 00:30:43 +00:00