[clang] [clang-tools-extra] [analyzer] Remove alpha.core.IdenticalExpr Checker (PR #114715)

Julian Schmidt via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 13 11:01:49 PST 2024


================
@@ -1238,6 +1235,59 @@ void RedundantExpressionCheck::check(const MatchFinder::MatchResult &Result) {
   if (const auto *BinOp = Result.Nodes.getNodeAs<BinaryOperator>("binary")) {
     // If the expression's constants are macros, check whether they are
     // intentional.
+
+    //
+    // Special case for floating-point representation.
+    //
+    // If expressions on both sides of comparison operator are of type float,
+    // then for some comparison operators no warning shall be
+    // reported even if the expressions are identical from a symbolic point of
+    // view. Comparison between expressions, declared variables and literals
+    // are treated differently.
+    //
+    // != and == between float literals that have the same value should NOT
+    // warn. < > between float literals that have the same value SHOULD warn.
+    //
+    // != and == between the same float declaration should NOT warn.
+    // < > between the same float declaration SHOULD warn.
+    //
+    // != and == between eq. expressions that evaluates into float
+    //           should NOT warn.
+    // < >       between eq. expressions that evaluates into float
+    //           should NOT warn.
+    //
+    const Expr *LHS = BinOp->getLHS()->IgnoreParenImpCasts();
+    const Expr *RHS = BinOp->getRHS()->IgnoreParenImpCasts();
+    BinaryOperator::Opcode Op = BinOp->getOpcode();
+
+    const auto *DeclRef1 = dyn_cast<DeclRefExpr>(LHS);
+    const auto *DeclRef2 = dyn_cast<DeclRefExpr>(RHS);
+    const auto *FloatLit1 = dyn_cast<FloatingLiteral>(LHS);
+    const auto *FloatLit2 = dyn_cast<FloatingLiteral>(RHS);
+    if ((DeclRef1) && (DeclRef2)) {
+      if ((DeclRef1->getType()->hasFloatingRepresentation()) &&
+          (DeclRef2->getType()->hasFloatingRepresentation())) {
+        if (DeclRef1->getDecl() == DeclRef2->getDecl()) {
+          if ((Op == BO_EQ) || (Op == BO_NE)) {
+            return;
+          }
+        }
+      }
+    } else if ((FloatLit1) && (FloatLit2)) {
+      if (FloatLit1->getValue().bitwiseIsEqual(FloatLit2->getValue())) {
+        if ((Op == BO_EQ) || (Op == BO_NE)) {
+          return;
+        }
+      }
----------------
5chmidti wrote:

Each of these two blocks of `if` statements could be combined with `&&` instead of keeping on nesting

https://github.com/llvm/llvm-project/pull/114715


More information about the cfe-commits mailing list