Added transfer function logic for ReturnStmts.
Fixed insidious bug in handling dereferences.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@46835 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/Analysis/GRConstants.cpp b/Analysis/GRConstants.cpp
index 516af28..65cb6e7 100644
--- a/Analysis/GRConstants.cpp
+++ b/Analysis/GRConstants.cpp
@@ -256,6 +256,8 @@
/// VisitBinaryOperator - Transfer function logic for binary operators.
void VisitBinaryOperator(BinaryOperator* B, NodeTy* Pred, NodeSet& Dst);
+ void VisitAssignmentLHS(Expr* E, NodeTy* Pred, NodeSet& Dst);
+
/// VisitDeclStmt - Transfer function logic for DeclStmts.
void VisitDeclStmt(DeclStmt* DS, NodeTy* Pred, NodeSet& Dst);
@@ -671,7 +673,7 @@
}
case UnaryOperator::Deref: {
- const LValue& L1 = GetLValue(St, U->getSubExpr());
+ const LValue& L1 = cast<LValue>(GetValue(St, U->getSubExpr()));
Nodify(Dst, U, N1, SetValue(St, U, GetValue(St, L1)));
break;
}
@@ -682,11 +684,31 @@
}
}
+void GRConstants::VisitAssignmentLHS(Expr* E, GRConstants::NodeTy* Pred,
+ GRConstants::NodeSet& Dst) {
+
+ if (isa<DeclRefExpr>(E))
+ return;
+
+ if (UnaryOperator* U = dyn_cast<UnaryOperator>(E)) {
+ if (U->getOpcode() == UnaryOperator::Deref) {
+ Visit(U->getSubExpr(), Pred, Dst);
+ return;
+ }
+ }
+
+ Visit(E, Pred, Dst);
+}
+
void GRConstants::VisitBinaryOperator(BinaryOperator* B,
GRConstants::NodeTy* Pred,
GRConstants::NodeSet& Dst) {
NodeSet S1;
- Visit(B->getLHS(), Pred, S1);
+
+ if (B->isAssignmentOp())
+ VisitAssignmentLHS(B->getLHS(), Pred, S1);
+ else
+ Visit(B->getLHS(), Pred, S1);
for (NodeSet::iterator I1=S1.begin(), E1=S1.end(); I1 != E1; ++I1) {
NodeTy* N1 = *I1;
@@ -712,6 +734,11 @@
if (Op <= BinaryOperator::Or) {
+ if (isa<InvalidValue>(V1) || isa<UninitializedValue>(V1)) {
+ Nodify(Dst, B, N2, SetValue(St, B, V1));
+ continue;
+ }
+
if (isa<LValue>(V1)) {
// FIXME: Add support for RHS being a non-lvalue.
const LValue& L1 = cast<LValue>(V1);
@@ -824,6 +851,14 @@
break;
}
+ case Stmt::ReturnStmtClass:
+ if (Expr* R = cast<ReturnStmt>(S)->getRetValue())
+ Visit(R, Pred, Dst);
+ else
+ Dst.Add(Pred);
+
+ break;
+
case Stmt::DeclStmtClass:
VisitDeclStmt(cast<DeclStmt>(S), Pred, Dst);
break;