From 72cb1aedb503db4157de20c97ca993aade36657f Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Mon, 29 Oct 2007 17:13:39 +0000 Subject: [PATCH] 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 --- Sema/SemaExpr.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Sema/SemaExpr.cpp b/Sema/SemaExpr.cpp index 13267eecec..e5412d41ad 100644 --- a/Sema/SemaExpr.cpp +++ b/Sema/SemaExpr.cpp @@ -1218,6 +1218,10 @@ inline QualType Sema::CheckCompareOperands( // C99 6.5.8 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(IgnoreParen(lex))) if (DeclRefExpr* DRR = dyn_cast(IgnoreParen(rex))) @@ -1229,7 +1233,12 @@ inline QualType Sema::CheckCompareOperands( // C99 6.5.8 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; -- 2.50.1