From b7135866e3127735bb93b0f7ebd813da355a9581 Mon Sep 17 00:00:00 2001 From: George Karpenkov Date: Wed, 13 Jun 2018 20:48:53 +0000 Subject: [PATCH] Update comments of CheckedArithmetic API based on Philip Reames feedback. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@334655 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Support/CheckedArithmetic.h | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/include/llvm/Support/CheckedArithmetic.h b/include/llvm/Support/CheckedArithmetic.h index 2ec27f4d354..039c374136f 100644 --- a/include/llvm/Support/CheckedArithmetic.h +++ b/include/llvm/Support/CheckedArithmetic.h @@ -41,16 +41,18 @@ checkedOp(T LHS, T RHS, F Op, bool Signed = true) { namespace llvm { -/// Add two signed integers \p LHS and \p RHS, return wrapped result if -/// available. +/// Add two signed integers \p LHS and \p RHS. +/// \return Optional of sum if no signed overflow occurred, +/// \c None otherwise. template typename std::enable_if::value, llvm::Optional>::type checkedAdd(T LHS, T RHS) { return checkedOp(LHS, RHS, &llvm::APInt::sadd_ov); } -/// Multiply two signed integers \p LHS and \p RHS, return wrapped result -/// if available. +/// Multiply two signed integers \p LHS and \p RHS. +/// \return Optional of product if no signed overflow occurred, +/// \c None otherwise. template typename std::enable_if::value, llvm::Optional>::type checkedMul(T LHS, T RHS) { @@ -58,7 +60,8 @@ checkedMul(T LHS, T RHS) { } /// Multiply A and B, and add C to the resulting product. -/// Return the value if available, None if overflowing. +/// \return Optional of result if no signed overflow occurred, +/// \c None otherwise. template typename std::enable_if::value, llvm::Optional>::type checkedMulAdd(T A, T B, T C) { @@ -67,24 +70,27 @@ checkedMulAdd(T A, T B, T C) { return llvm::None; } -/// Add two unsigned integers \p LHS and \p RHS, return wrapped result -/// if available. +/// Add two unsigned integers \p LHS and \p RHS. +/// \return Optional of sum if no unsigned overflow occurred, +/// \c None otherwise. template typename std::enable_if::value, llvm::Optional>::type checkedAddUnsigned(T LHS, T RHS) { return checkedOp(LHS, RHS, &llvm::APInt::uadd_ov, /*Signed=*/false); } -/// Multiply two unsigned integers \p LHS and \p RHS, return wrapped result -/// if available. +/// Multiply two unsigned integers \p LHS and \p RHS. +/// \return Optional of product if no unsigned overflow occurred, +/// \c None otherwise. template typename std::enable_if::value, llvm::Optional>::type checkedMulUnsigned(T LHS, T RHS) { return checkedOp(LHS, RHS, &llvm::APInt::umul_ov, /*Signed=*/false); } -/// Multiply unsigned A and B, and add C to the resulting product. -/// Return the value if available, None if overflowing. +/// Multiply unsigned integers A and B, and add C to the resulting product. +/// \return Optional of result if no unsigned overflow occurred, +/// \c None otherwise. template typename std::enable_if::value, llvm::Optional>::type checkedMulAddUnsigned(T A, T B, T C) { -- 2.11.0