Author: phyBrackets Date: 2022-02-13T00:15:35+05:30 New Revision: de4e855204aab9ecf0507f57341cad9c349b3c49
URL: https://github.com/llvm/llvm-project/commit/de4e855204aab9ecf0507f57341cad9c349b3c49 DIFF: https://github.com/llvm/llvm-project/commit/de4e855204aab9ecf0507f57341cad9c349b3c49.diff LOG: Refactor nested if else with ternary operator in CGExprScalar.cpp Reviewed By: rjmccall Differential Revision: https://reviews.llvm.org/D119364 Added: Modified: clang/lib/CodeGen/CGExprScalar.cpp Removed: ################################################################################ diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp index 59d0bd08d33d2..a235639054935 100644 --- a/clang/lib/CodeGen/CGExprScalar.cpp +++ b/clang/lib/CodeGen/CGExprScalar.cpp @@ -65,20 +65,14 @@ bool mayHaveIntegerOverflow(llvm::ConstantInt *LHS, llvm::ConstantInt *RHS, const auto &LHSAP = LHS->getValue(); const auto &RHSAP = RHS->getValue(); if (Opcode == BO_Add) { - if (Signed) - Result = LHSAP.sadd_ov(RHSAP, Overflow); - else - Result = LHSAP.uadd_ov(RHSAP, Overflow); + Result = Signed ? LHSAP.sadd_ov(RHSAP, Overflow) + : LHSAP.uadd_ov(RHSAP, Overflow); } else if (Opcode == BO_Sub) { - if (Signed) - Result = LHSAP.ssub_ov(RHSAP, Overflow); - else - Result = LHSAP.usub_ov(RHSAP, Overflow); + Result = Signed ? LHSAP.ssub_ov(RHSAP, Overflow) + : LHSAP.usub_ov(RHSAP, Overflow); } else if (Opcode == BO_Mul) { - if (Signed) - Result = LHSAP.smul_ov(RHSAP, Overflow); - else - Result = LHSAP.umul_ov(RHSAP, Overflow); + Result = Signed ? LHSAP.smul_ov(RHSAP, Overflow) + : LHSAP.umul_ov(RHSAP, Overflow); } else if (Opcode == BO_Div || Opcode == BO_Rem) { if (Signed && !RHS->isZero()) Result = LHSAP.sdiv_ov(RHSAP, Overflow); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits