diff options
author | Ted Kremenek <kremenek@apple.com> | 2012-11-29 00:50:20 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2012-11-29 00:50:20 +0000 |
commit | 9c0466603f2051fec9270686dfcd270630e62530 (patch) | |
tree | 108b55fbd46028852b6e0443e86edf26c20abee7 /lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp | |
parent | 586a061ad96f750e2a5aefcf3e2ce9e5474cdd61 (diff) |
Correctly handle IntegralToBool casts in C++ in the static analyzer. Fixes <rdar://problem/12759044>.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@168843 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp')
-rw-r--r-- | lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp b/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp index fbc6ba0551..12da82e3f0 100644 --- a/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp +++ b/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp @@ -101,6 +101,12 @@ SVal SimpleSValBuilder::evalCastFromNonLoc(NonLoc val, QualType castTy) { if (!isa<nonloc::ConcreteInt>(val)) return UnknownVal(); + // Handle casts to a boolean type. + if (castTy->isBooleanType()) { + bool b = cast<nonloc::ConcreteInt>(val).getValue().getBoolValue(); + return makeTruthVal(b, castTy); + } + // Only handle casts from integers to integers - if val is an integer constant // being cast to a non integer type, produce unknown. if (!isLocType && !castTy->isIntegerType()) @@ -735,7 +741,7 @@ SVal SimpleSValBuilder::evalBinOpLL(ProgramStateRef state, NonLoc *LeftIndex = dyn_cast<NonLoc>(&LeftIndexVal); if (!LeftIndex) return UnknownVal(); - LeftIndexVal = evalCastFromNonLoc(*LeftIndex, resultTy); + LeftIndexVal = evalCastFromNonLoc(*LeftIndex, ArrayIndexTy); LeftIndex = dyn_cast<NonLoc>(&LeftIndexVal); if (!LeftIndex) return UnknownVal(); @@ -745,7 +751,7 @@ SVal SimpleSValBuilder::evalBinOpLL(ProgramStateRef state, NonLoc *RightIndex = dyn_cast<NonLoc>(&RightIndexVal); if (!RightIndex) return UnknownVal(); - RightIndexVal = evalCastFromNonLoc(*RightIndex, resultTy); + RightIndexVal = evalCastFromNonLoc(*RightIndex, ArrayIndexTy); RightIndex = dyn_cast<NonLoc>(&RightIndexVal); if (!RightIndex) return UnknownVal(); |