aboutsummaryrefslogtreecommitdiff
path: root/Analysis/GRConstants.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2008-01-23 23:42:27 +0000
committerTed Kremenek <kremenek@apple.com>2008-01-23 23:42:27 +0000
commit2eafd0ebf19c879c9bc0061499ed788a1f5d1f71 (patch)
treebcdf66a71536ed143709db5d556e85b80dce39bf /Analysis/GRConstants.cpp
parentb4ae33fe42ff0605cca15c5657bbdf063ef8f9be (diff)
Implemented value tracking support for '*' and '*='.
Added "multiplication" support for equality sets. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@46289 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'Analysis/GRConstants.cpp')
-rw-r--r--Analysis/GRConstants.cpp39
1 files changed, 38 insertions, 1 deletions
diff --git a/Analysis/GRConstants.cpp b/Analysis/GRConstants.cpp
index 84cc200d11..62b007ab30 100644
--- a/Analysis/GRConstants.cpp
+++ b/Analysis/GRConstants.cpp
@@ -206,6 +206,7 @@ protected:
public:
RValue Add(ValueManager& ValMgr, const RValue& RHS) const;
RValue Sub(ValueManager& ValMgr, const RValue& RHS) const;
+ RValue Mul(ValueManager& ValMgr, const RValue& RHS) const;
static RValue GetRValue(ValueManager& ValMgr, IntegerLiteral* S);
@@ -225,7 +226,8 @@ public:
}
RValueMayEqualSet Add(ValueManager& ValMgr, const RValueMayEqualSet& V) const;
- RValueMayEqualSet Sub(ValueManager& ValMgr, const RValueMayEqualSet& V) const;
+ RValueMayEqualSet Sub(ValueManager& ValMgr, const RValueMayEqualSet& V) const;
+ RValueMayEqualSet Mul(ValueManager& ValMgr, const RValueMayEqualSet& V) const;
// Implement isa<T> support.
static inline bool classof(const ExprValue* V) {
@@ -259,6 +261,10 @@ RValue RValue::Sub(ValueManager& ValMgr, const RValue& RHS) const {
RVALUE_DISPATCH(Sub)
}
+RValue RValue::Mul(ValueManager& ValMgr, const RValue& RHS) const {
+ RVALUE_DISPATCH(Mul)
+}
+
#undef RVALUE_DISPATCH_CASE
#undef RVALUE_DISPATCH
@@ -294,6 +300,22 @@ RValueMayEqualSet::Sub(ValueManager& ValMgr,
return M;
}
+RValueMayEqualSet
+RValueMayEqualSet::Mul(ValueManager& ValMgr,
+ const RValueMayEqualSet& RHS) const {
+
+ APSIntSetTy S1 = GetValues();
+ APSIntSetTy S2 = RHS.GetValues();
+
+ APSIntSetTy M = ValMgr.GetEmptyAPSIntSet();
+
+ for (APSIntSetTy::iterator I1=S1.begin(), E1=S2.end(); I1!=E1; ++I1)
+ for (APSIntSetTy::iterator I2=S2.begin(), E2=S2.end(); I2!=E2; ++I2)
+ M = ValMgr.AddToSet(M, *I1 * *I2);
+
+ return M;
+}
+
RValue RValue::GetRValue(ValueManager& ValMgr, IntegerLiteral* S) {
return RValueMayEqualSet(ValMgr.AddToSet(ValMgr.GetEmptyAPSIntSet(),
S->getValue()));
@@ -668,6 +690,13 @@ void GRConstants::VisitBinaryOperator(BinaryOperator* B,
break;
}
+ case BinaryOperator::Mul: {
+ const RValue& R1 = cast<RValue>(V1);
+ const RValue& R2 = cast<RValue>(V2);
+ Nodify(Dst, B, N2, SetValue(St, B, R1.Mul(ValMgr, R2)));
+ break;
+ }
+
case BinaryOperator::Assign: {
const LValue& L1 = cast<LValue>(V1);
const RValue& R2 = cast<RValue>(V2);
@@ -690,6 +719,14 @@ void GRConstants::VisitBinaryOperator(BinaryOperator* B,
Nodify(Dst, B, N2, SetValue(SetValue(St, B, Result), L1, Result));
break;
}
+
+ case BinaryOperator::MulAssign: {
+ const LValue& L1 = cast<LValue>(V1);
+ RValue R1 = cast<RValue>(GetValue(N1->getState(), L1));
+ RValue Result = R1.Mul(ValMgr, cast<RValue>(V2));
+ Nodify(Dst, B, N2, SetValue(SetValue(St, B, Result), L1, Result));
+ break;
+ }
default:
Dst.Add(N2);