[cfe-commits] r43447 - in /cfe/trunk: Sema/SemaExpr.cpp test/Sema/floating-point-compare.c
Ted Kremenek
kremenek at apple.com
Mon Oct 29 09:40:01 PDT 2007
Author: kremenek
Date: Mon Oct 29 11:40:01 2007
New Revision: 43447
URL: http://llvm.org/viewvc/llvm-project?rev=43447&view=rev
Log:
For checking for floating point comparison using == or !=, we now suppress
errors for cases such as "x == x".
Added test case to test this feature.
Modified:
cfe/trunk/Sema/SemaExpr.cpp
cfe/trunk/test/Sema/floating-point-compare.c
Modified: cfe/trunk/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaExpr.cpp?rev=43447&r1=43446&r2=43447&view=diff
==============================================================================
--- cfe/trunk/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/Sema/SemaExpr.cpp Mon Oct 29 11:40:01 2007
@@ -1208,9 +1208,19 @@
if (lType->isRealType() && rType->isRealType())
return Context.IntTy;
} else {
- if (lType->isFloatingType() && rType->isFloatingType())
- Diag(loc, diag::warn_floatingpoint_eq);
-
+ if (lType->isFloatingType() && rType->isFloatingType()) {
+ // Special case: check for x == x (which is OK).
+ bool EmitWarning = true;
+
+ if (DeclRefExpr* DRL = dyn_cast<DeclRefExpr>(lex))
+ if (DeclRefExpr* DRR = dyn_cast<DeclRefExpr>(rex))
+ if (DRL->getDecl() == DRR->getDecl())
+ EmitWarning = false;
+
+ if (EmitWarning)
+ Diag(loc, diag::warn_floatingpoint_eq);
+ }
+
if (lType->isArithmeticType() && rType->isArithmeticType())
return Context.IntTy;
}
Modified: cfe/trunk/test/Sema/floating-point-compare.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/floating-point-compare.c?rev=43447&r1=43446&r2=43447&view=diff
==============================================================================
--- cfe/trunk/test/Sema/floating-point-compare.c (original)
+++ cfe/trunk/test/Sema/floating-point-compare.c Mon Oct 29 11:40:01 2007
@@ -7,3 +7,7 @@
int bar(float x, float y) {
return x != y; // expected-warning {{comparing floating point with ==}}
}
+
+int qux(float x) {
+ return x == x; // no-warning
+}
More information about the cfe-commits
mailing list