From: Jordan Rose Date: Wed, 18 Sep 2013 18:58:58 +0000 (+0000) Subject: [analyzer] Don't even try to convert floats to booleans for now. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d76cec5567cb5b04cb5cc48a477a0c71b910053c;p=clang [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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@190953 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/StaticAnalyzer/Core/SValBuilder.cpp b/lib/StaticAnalyzer/Core/SValBuilder.cpp index d615d3f577..2142f06fef 100644 --- a/lib/StaticAnalyzer/Core/SValBuilder.cpp +++ b/lib/StaticAnalyzer/Core/SValBuilder.cpp @@ -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 index 0000000000..339539189e --- /dev/null +++ b/test/Analysis/casts.cpp @@ -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; +}