]> granicus.if.org Git - clang/commitdiff
In the "use of floating point variable as loop counter" check, check
authorTed Kremenek <kremenek@apple.com>
Fri, 24 Jul 2009 20:26:31 +0000 (20:26 +0000)
committerTed Kremenek <kremenek@apple.com>
Fri, 24 Jul 2009 20:26:31 +0000 (20:26 +0000)
if the DeclRefExpr is a float, not just either argument.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@76998 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/CheckSecuritySyntaxOnly.cpp

index 5c98a526b7f6361f78024828ffd56e05e786342b..17fc6d7c32ed911a26299fd246e0b83ee8ae1df6 100644 (file)
@@ -143,16 +143,18 @@ void WalkAST::CheckLoopConditionForFloat(const ForStmt *FS) {
   if (!B)
     return;
   
-  // The actual error condition.
-  if (!((B->isRelationalOp() || B->isEqualityOp()) &&
-        ((B->getLHS()->getType()->isFloatingType() ||
-          B->getRHS()->getType()->isFloatingType()))))
+  // Is this a comparison?
+  if (!(B->isRelationalOp() || B->isEqualityOp()))
     return;
-  
+      
   // Are we comparing variables?
   const DeclRefExpr *drLHS = dyn_cast<DeclRefExpr>(B->getLHS()->IgnoreParens());
   const DeclRefExpr *drRHS = dyn_cast<DeclRefExpr>(B->getRHS()->IgnoreParens());
   
+  // Does at least one of the variables have a floating point type?
+  drLHS = drLHS && drLHS->getType()->isFloatingType() ? drLHS : NULL;
+  drRHS = drRHS && drRHS->getType()->isFloatingType() ? drRHS : NULL;
+  
   if (!drLHS && !drRHS)
     return;