[cfe-commits] r44058 - in /cfe/trunk: Sema/SemaExpr.cpp test/Sema/floating-point-compare.c
Ted Kremenek
kremenek at apple.com
Tue Nov 13 11:17:00 PST 2007
Author: kremenek
Date: Tue Nov 13 13:17:00 2007
New Revision: 44058
URL: http://llvm.org/viewvc/llvm-project?rev=44058&view=rev
Log:
Modified -Wfloat-equal logic to suppress warnings where floating point values
are compared against builtins such as __builtin_inf.
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=44058&r1=44057&r2=44058&view=diff
==============================================================================
--- cfe/trunk/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/Sema/SemaExpr.cpp Tue Nov 13 13:17:00 2007
@@ -1218,6 +1218,33 @@
return E;
}
+// Utility method to plow through parenthesis and casts.
+static inline Expr* IgnoreParenCasts(Expr* E) {
+ while(true) {
+ if (ParenExpr* P = dyn_cast<ParenExpr>(E))
+ E = P->getSubExpr();
+ else if (CastExpr* P = dyn_cast<CastExpr>(E))
+ E = P->getSubExpr();
+ else if (ImplicitCastExpr* P = dyn_cast<ImplicitCastExpr>(E))
+ E = P->getSubExpr();
+ else
+ break;
+ }
+
+ return E;
+}
+
+// Utility method to determine if a CallExpr is a call to a builtin.
+static inline bool isCallBuiltin(CallExpr* cexp) {
+ Expr* sub = IgnoreParenCasts(cexp->getCallee());
+
+ if (DeclRefExpr* E = dyn_cast<DeclRefExpr>(sub))
+ if (E->getDecl()->getIdentifier()->getBuiltinID() > 0)
+ return true;
+
+ return false;
+}
+
inline QualType Sema::CheckCompareOperands( // C99 6.5.8
Expr *&lex, Expr *&rex, SourceLocation loc, bool isRelational)
{
@@ -1254,11 +1281,27 @@
// Special case: check for x == x (which is OK).
bool EmitWarning = true;
- if (DeclRefExpr* DRL = dyn_cast<DeclRefExpr>(IgnoreParen(lex)))
- if (DeclRefExpr* DRR = dyn_cast<DeclRefExpr>(IgnoreParen(rex)))
+ Expr* LeftExprSansParen = IgnoreParen(lex);
+ Expr* RightExprSansParen = IgnoreParen(rex);
+
+ // Look for x == x. Do not emit warnings for such cases.
+ if (DeclRefExpr* DRL = dyn_cast<DeclRefExpr>(LeftExprSansParen))
+ if (DeclRefExpr* DRR = dyn_cast<DeclRefExpr>(RightExprSansParen))
if (DRL->getDecl() == DRR->getDecl())
EmitWarning = false;
+
+ // Check for comparisons with builtin types.
+ if (EmitWarning)
+ if (CallExpr* CL = dyn_cast<CallExpr>(LeftExprSansParen))
+ if (isCallBuiltin(CL))
+ EmitWarning = false;
+ if (EmitWarning)
+ if (CallExpr* CR = dyn_cast<CallExpr>(RightExprSansParen))
+ if (isCallBuiltin(CR))
+ EmitWarning = false;
+
+ // Emit the diagnostic.
if (EmitWarning)
Diag(loc, diag::warn_floatingpoint_eq,
lex->getSourceRange(),rex->getSourceRange());
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=44058&r1=44057&r2=44058&view=diff
==============================================================================
--- cfe/trunk/test/Sema/floating-point-compare.c (original)
+++ cfe/trunk/test/Sema/floating-point-compare.c Tue Nov 13 13:17:00 2007
@@ -11,3 +11,11 @@
int qux(float x) {
return x == x; // no-warning
}
+
+int baz(float x) {
+ return x == 0.0; // no-warning
+}
+
+int taz(float x) {
+ return x == __builtin_inf(); // no-warning
+}
\ No newline at end of file
More information about the cfe-commits
mailing list