[clang] de4e855 - Refactor nested if else with ternary operator in CGExprScalar.cpp
via cfe-commits
cfe-commits at lists.llvm.org
Sat Feb 12 10:45:41 PST 2022
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);
More information about the cfe-commits
mailing list