Added some comments.
Moved a dependent predicate in an if statement to be an assertion
within the if statement body.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43453 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/Sema/SemaExpr.cpp b/Sema/SemaExpr.cpp
index 13267ee..e5412d4 100644
--- a/Sema/SemaExpr.cpp
+++ b/Sema/SemaExpr.cpp
@@ -1218,6 +1218,10 @@
QualType lType = lex->getType();
QualType rType = rex->getType();
+
+ // For non-floating point types, check for self-comparisons of the form
+ // x == x, x != x, x < x, etc. These always evaluate to a constant, and
+ // often indicate logic errors in the program.
if (!lType->isFloatingType()) {
if (DeclRefExpr* DRL = dyn_cast<DeclRefExpr>(IgnoreParen(lex)))
if (DeclRefExpr* DRR = dyn_cast<DeclRefExpr>(IgnoreParen(rex)))
@@ -1229,7 +1233,12 @@
if (lType->isRealType() && rType->isRealType())
return Context.IntTy;
} else {
- if (lType->isFloatingType() && rType->isFloatingType()) {
+ // Check for comparisons of floating point operands using != and ==.
+ // Issue a warning if these are no self-comparisons, as they are not likely
+ // to do what the programmer intended.
+ if (lType->isFloatingType()) {
+ assert (rType->isFloatingType());
+
// Special case: check for x == x (which is OK).
bool EmitWarning = true;