diff options
author | Ted Kremenek <kremenek@apple.com> | 2008-12-03 19:06:30 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2008-12-03 19:06:30 +0000 |
commit | fff9f4aaafd2735e96f76148caa337c6a8ac73de (patch) | |
tree | 5a22ea57646d930c978062c87b6f2c0ec339c4eb /clang/lib/Analysis/BasicConstraintManager.cpp | |
parent | f935cfe277fbf839ba149b45b6d27418a8e16a8c (diff) | |
download | bcm5719-llvm-fff9f4aaafd2735e96f76148caa337c6a8ac73de.tar.gz bcm5719-llvm-fff9f4aaafd2735e96f76148caa337c6a8ac73de.zip |
BasicConstraintManager:
- Fix nonsensical logic in AssumeSymGE. When comparing 'sym >= constant' and the
constant is the maximum integer value, add the constraint that 'sym ==
constant' when the path is deemed feasible. All other cases are feasible.
- Improve AssumeSymGT. When comparing 'sym > constant' and constant is the
maximum integer value we know the path is infeasible.
- Add test case for this enhancement to AssumeSymGT.
llvm-svn: 60490
Diffstat (limited to 'clang/lib/Analysis/BasicConstraintManager.cpp')
-rw-r--r-- | clang/lib/Analysis/BasicConstraintManager.cpp | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/clang/lib/Analysis/BasicConstraintManager.cpp b/clang/lib/Analysis/BasicConstraintManager.cpp index c8065d18690..f4290ffb67d 100644 --- a/clang/lib/Analysis/BasicConstraintManager.cpp +++ b/clang/lib/Analysis/BasicConstraintManager.cpp @@ -328,6 +328,13 @@ const GRState* BasicConstraintManager::AssumeSymGT(const GRState* St, SymbolID sym, const llvm::APSInt& V, bool& isFeasible) { + // Is 'V' the largest possible value? + if (V == llvm::APSInt::getMaxValue(V.getBitWidth(), V.isSigned())) { + // sym cannot be any value greater than 'V'. This path is infeasible. + isFeasible = false; + return St; + } + // FIXME: For now have assuming x > y be the same as assuming sym != V; return AssumeSymNE(St, sym, V, isFeasible); } @@ -341,10 +348,23 @@ BasicConstraintManager::AssumeSymGE(const GRState* St, SymbolID sym, isFeasible = *X >= V; return St; } + + // Sym is not a constant, but it is worth looking to see if V is the + // maximum integer value. + if (V == llvm::APSInt::getMaxValue(V.getBitWidth(), V.isSigned())) { + // If we know that sym != V, then this condition is infeasible since + // there is no other value greater than V. + isFeasible = !isNotEqual(St, sym, V); + + // If the path is still feasible then as a consequence we know that + // 'sym == V' because we cannot have 'sym > V' (no larger values). + // Add this constraint. + if (isFeasible) + return AddEQ(St, sym, V); + } + else + isFeasible = true; - isFeasible = !isNotEqual(St, sym, V) || - (V != llvm::APSInt::getMaxValue(V.getBitWidth(), V.isSigned())); - return St; } |