[cfe-commits] r112932 - /cfe/trunk/lib/Checker/SimpleSValuator.cpp
Ted Kremenek
kremenek at apple.com
Thu Sep 2 18:07:06 PDT 2010
Author: kremenek
Date: Thu Sep 2 20:07:06 2010
New Revision: 112932
URL: http://llvm.org/viewvc/llvm-project?rev=112932&view=rev
Log:
Support pointer arithmetic in SimpleSValuator involving direct constants.
Modified:
cfe/trunk/lib/Checker/SimpleSValuator.cpp
Modified: cfe/trunk/lib/Checker/SimpleSValuator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Checker/SimpleSValuator.cpp?rev=112932&r1=112931&r2=112932&view=diff
==============================================================================
--- cfe/trunk/lib/Checker/SimpleSValuator.cpp (original)
+++ cfe/trunk/lib/Checker/SimpleSValuator.cpp Thu Sep 2 20:07:06 2010
@@ -833,8 +833,43 @@
}
}
}
+
+ // We are dealing with pointer arithmetic.
- // Delegate pointer arithmetic to the StoreManager.
+ // Handle pointer arithmetic on constant values.
+ if (nonloc::ConcreteInt *rhsInt = dyn_cast<nonloc::ConcreteInt>(&rhs)) {
+ if (loc::ConcreteInt *lhsInt = dyn_cast<loc::ConcreteInt>(&lhs)) {
+ const llvm::APSInt &leftI = lhsInt->getValue();
+ assert(leftI.isUnsigned());
+ llvm::APSInt rightI(rhsInt->getValue(), /* isUnsigned */ true);
+
+ // Convert the bitwidth of rightI. This should deal with overflow
+ // since we are dealing with concrete values.
+ rightI.extOrTrunc(leftI.getBitWidth());
+
+ // Offset the increment by the pointer size.
+ ASTContext &ctx = ValMgr.getContext();
+ const PointerType *PT = resultTy->getAs<PointerType>();
+ llvm::APSInt Multiplicand(rightI.getBitWidth(), /* isUnsigned */ true);
+ rightI *= Multiplicand;
+
+ // Compute the adjusted pointer.
+ switch (op) {
+ case BO_Add:
+ rightI = leftI + rightI;
+ break;
+ case BO_Sub:
+ rightI = leftI - rightI;
+ break;
+ default:
+ llvm_unreachable("Invalid pointer arithmetic operation");
+ }
+ return loc::ConcreteInt(ValMgr.getBasicValueFactory().getValue(rightI));
+ }
+ }
+
+
+ // Delegate remaining pointer arithmetic to the StoreManager.
return state->getStateManager().getStoreManager().EvalBinOp(op, lhs,
rhs, resultTy);
}
More information about the cfe-commits
mailing list