From: Argyrios Kyrtzidis Date: Sat, 19 Feb 2011 01:59:41 +0000 (+0000) Subject: [analyzer] Fix crash when analyzing C++ code. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=370e6e984cc32167228b66eaf9610c010da0d794;p=clang [analyzer] Fix crash when analyzing C++ code. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@126013 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h b/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h index e7b39448ac..fc2b76e04a 100644 --- a/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h +++ b/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h @@ -172,9 +172,8 @@ public: I->getType()->isUnsignedIntegerType())); } - nonloc::ConcreteInt makeIntVal(const CXXBoolLiteralExpr *E) { - return E->getValue() ? nonloc::ConcreteInt(BasicVals.getValue(1, 1, true)) - : nonloc::ConcreteInt(BasicVals.getValue(0, 1, true)); + nonloc::ConcreteInt makeBoolVal(const CXXBoolLiteralExpr *E) { + return makeTruthVal(E->getValue()); } nonloc::ConcreteInt makeIntVal(const llvm::APSInt& V) { @@ -218,11 +217,11 @@ public: NonLoc makeNonLoc(const SymExpr *lhs, BinaryOperator::Opcode op, const SymExpr *rhs, QualType T); - NonLoc makeTruthVal(bool b, QualType T) { + nonloc::ConcreteInt makeTruthVal(bool b, QualType T) { return nonloc::ConcreteInt(BasicVals.getTruthValue(b, T)); } - NonLoc makeTruthVal(bool b) { + nonloc::ConcreteInt makeTruthVal(bool b) { return nonloc::ConcreteInt(BasicVals.getTruthValue(b)); } diff --git a/lib/StaticAnalyzer/Core/Environment.cpp b/lib/StaticAnalyzer/Core/Environment.cpp index 33f1945ce7..ecaff295b3 100644 --- a/lib/StaticAnalyzer/Core/Environment.cpp +++ b/lib/StaticAnalyzer/Core/Environment.cpp @@ -45,7 +45,7 @@ SVal Environment::getSVal(const Stmt *E, SValBuilder& svalBuilder) const { if (X) return *X; else - return svalBuilder.makeIntVal(cast(E)); + return svalBuilder.makeBoolVal(cast(E)); } case Stmt::IntegerLiteralClass: { // In C++, this expression may have been bound to a temporary object. diff --git a/test/Analysis/cxx-crashes.cpp b/test/Analysis/cxx-crashes.cpp index c15eea862e..cebc55bd42 100644 --- a/test/Analysis/cxx-crashes.cpp +++ b/test/Analysis/cxx-crashes.cpp @@ -10,6 +10,10 @@ long f2(char *c) { return long(c) & 1; } +bool f3() { + return !false; +} + namespace { struct A { };