[llvm-branch-commits] [clang] 4f72fba - Refactor nested if else with ternary operator in CGExprScalar.cpp

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Sat Feb 12 10:29:18 PST 2022


Author: phyBrackets
Date: 2022-02-11T22:34:05+05:30
New Revision: 4f72fbab3d1456be8e14185443b5271df21eb995

URL: https://github.com/llvm/llvm-project/commit/4f72fbab3d1456be8e14185443b5271df21eb995
DIFF: https://github.com/llvm/llvm-project/commit/4f72fbab3d1456be8e14185443b5271df21eb995.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);


        


More information about the llvm-branch-commits mailing list