]> granicus.if.org Git - clang/commitdiff
[analyzer] Don't even try to convert floats to booleans for now.
authorJordan Rose <jordan_rose@apple.com>
Wed, 18 Sep 2013 18:58:58 +0000 (18:58 +0000)
committerJordan Rose <jordan_rose@apple.com>
Wed, 18 Sep 2013 18:58:58 +0000 (18:58 +0000)
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.

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

lib/StaticAnalyzer/Core/SValBuilder.cpp
test/Analysis/casts.cpp [new file with mode: 0644]

index d615d3f5774878e3627610a00dcbf0733e291ee4..2142f06fef51846e7cc31b8d4920ba966bb099f2 100644 (file)
@@ -405,6 +405,10 @@ SVal SValBuilder::evalCast(SVal val, QualType castTy, QualType originalTy) {
       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
diff --git a/test/Analysis/casts.cpp b/test/Analysis/casts.cpp
new file mode 100644 (file)
index 0000000..3395391
--- /dev/null
@@ -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;
+}