Provide checkedAdd and checkedMul functions, providing checked arithmetic on signed 64 bit integers.
Details
Diff Detail
- Repository
- rL LLVM
Event Timeline
It would be great to have checked* utilities which work with all the different kinds of integers.
include/llvm/Support/MathExtras.h | ||
---|---|---|
852 ↗ | (On Diff #135743) | Once this lands, I think people will want to use it for more than just int64_t. To make this generic we'll need templates, and that introduces a cyclic-dependency problem with APInt.h. Sorry for not thinking of this earlier, but: wdyt of moving this to Support/CheckedArithmetic.h (or similar)? |
lib/Support/MathExtras.cpp | ||
21 ↗ | (On Diff #135743) | Could you move the APInt include up to the right spot? |
26 ↗ | (On Diff #135743) | Please clang-format your diffs. |
29 ↗ | (On Diff #135743) | llvm::function_ref is more appropriate for non-owning callables. |
lib/Support/MathExtras.cpp | ||
---|---|---|
29 ↗ | (On Diff #135743) | ...except it does not work here, and I don't think it's worth it to investigate why |
include/llvm/Support/CheckedArithmetic.h | ||
---|---|---|
33 ↗ | (On Diff #135765) | Could you elaborate? |
include/llvm/Support/CheckedArithmetic.h | ||
---|---|---|
33 ↗ | (On Diff #135765) | I'm suggesting adding 'typename F' to the template parameter list and using F as the type of Op. It's shorter, and since there's no std::function, it signals to the reader that there are no unnecessary copies happening. Taken together this makes the code easier to read. |
Thanks! Please wait a day or so before committing to give others time to provide feedback.
include/llvm/Support/CheckedArithmetic.h | ||
---|---|---|
20 ↗ | (On Diff #135972) | This include can go away now. |