summaryrefslogtreecommitdiffstats
path: root/clang/lib/Analysis/BasicConstraintManager.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2008-09-16 23:24:45 +0000
committerTed Kremenek <kremenek@apple.com>2008-09-16 23:24:45 +0000
commit8782716c4a681bacddc46ea38de5cc6bd4d41530 (patch)
treef5e5efe70942afed921b307fa7a3ae4a5ddd428d /clang/lib/Analysis/BasicConstraintManager.cpp
parent2b4b3b13a954134f3e548c828faa398a532946ea (diff)
downloadbcm5719-llvm-8782716c4a681bacddc46ea38de5cc6bd4d41530.tar.gz
bcm5719-llvm-8782716c4a681bacddc46ea38de5cc6bd4d41530.zip
Minor pass-sensitivity improvement:
if we know that 'len != 0' and know that 'i == 0' then we know that 'i < len' must evaluate to true and cannot evaluate to false llvm-svn: 56260
Diffstat (limited to 'clang/lib/Analysis/BasicConstraintManager.cpp')
-rw-r--r--clang/lib/Analysis/BasicConstraintManager.cpp29
1 files changed, 25 insertions, 4 deletions
diff --git a/clang/lib/Analysis/BasicConstraintManager.cpp b/clang/lib/Analysis/BasicConstraintManager.cpp
index ca97f930ddb..2edbd803416 100644
--- a/clang/lib/Analysis/BasicConstraintManager.cpp
+++ b/clang/lib/Analysis/BasicConstraintManager.cpp
@@ -228,6 +228,12 @@ BasicConstraintManager::AssumeSymInt(const GRState* St, bool Assumption,
else
return AssumeSymLT(St, C.getSymbol(), C.getInt(), isFeasible);
+ case BinaryOperator::LT:
+ if (Assumption)
+ return AssumeSymLT(St, C.getSymbol(), C.getInt(), isFeasible);
+ else
+ return AssumeSymGE(St, C.getSymbol(), C.getInt(), isFeasible);
+
case BinaryOperator::LE:
if (Assumption)
return AssumeSymLE(St, C.getSymbol(), C.getInt(), isFeasible);
@@ -302,15 +308,30 @@ const GRState*
BasicConstraintManager::AssumeSymGE(const GRState* St, SymbolID sym,
const llvm::APSInt& V, bool& isFeasible) {
- // FIXME: Primitive logic for now. Only reject a path if the value of
- // sym is a constant X and !(X >= V).
-
+ // Reject a path if the value of sym is a constant X and !(X >= V).
if (const llvm::APSInt* X = getSymVal(St, sym)) {
isFeasible = *X >= V;
return St;
}
- isFeasible = true;
+ // sym is not a constant, but it might be not-equal to a constant.
+ // Observe: V >= sym is the same as sym <= V.
+ // check: is sym != V?
+ // check: is sym > V?
+ // if both are true, the path is infeasible.
+
+ if (isNotEqual(St, sym, V)) {
+ // Is sym > V?
+ //
+ // We're not doing heavy range analysis yet, so all we can accurately
+ // reason about are the edge cases.
+ //
+ // If V == 0, since we know that sym != V, we also know that sym > V.
+ isFeasible = V != 0;
+ }
+ else
+ isFeasible = true;
+
return St;
}
OpenPOWER on IntegriCloud