r190953 - [analyzer] Don't even try to convert floats to booleans for now.

Jordan Rose jordan_rose at apple.com
Wed Sep 18 11:58:58 PDT 2013


Author: jrose
Date: Wed Sep 18 13:58:58 2013
New Revision: 190953

URL: http://llvm.org/viewvc/llvm-project?rev=190953&view=rev
Log:
[analyzer] Don't even try to convert floats to booleans for now.

We now have symbols with floating-point type to make sure that
(double)x == (double)x comes out true, but we still can't do much with
these. For now, don't even bother trying to create a floating-point zero
value; just give up on conversion to bool.

PR14634, C++ edition.

Added:
    cfe/trunk/test/Analysis/casts.cpp
Modified:
    cfe/trunk/lib/StaticAnalyzer/Core/SValBuilder.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Core/SValBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/SValBuilder.cpp?rev=190953&r1=190952&r2=190953&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/SValBuilder.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/SValBuilder.cpp Wed Sep 18 13:58:58 2013
@@ -405,6 +405,10 @@ SVal SValBuilder::evalCast(SVal val, Qua
       return val;
     if (val.isConstant())
       return makeTruthVal(!val.isZeroConstant(), castTy);
+    if (!Loc::isLocType(originalTy) &&
+        !originalTy->isIntegralOrEnumerationType() &&
+        !originalTy->isMemberPointerType())
+      return UnknownVal();
     if (SymbolRef Sym = val.getAsSymbol(true)) {
       BasicValueFactory &BVF = getBasicValueFactory();
       // FIXME: If we had a state here, we could see if the symbol is known to

Added: cfe/trunk/test/Analysis/casts.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/casts.cpp?rev=190953&view=auto
==============================================================================
--- cfe/trunk/test/Analysis/casts.cpp (added)
+++ cfe/trunk/test/Analysis/casts.cpp Wed Sep 18 13:58:58 2013
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -analyze -analyzer-checker=core -analyzer-store=region -verify %s
+// expected-no-diagnostics
+
+bool PR14634(int x) {
+  double y = (double)x;
+  return !y;
+}
+
+bool PR14634_implicit(int x) {
+  double y = (double)x;
+  return y;
+}





More information about the cfe-commits mailing list